Swift version: 5.2
When Auto Layout has determined there isn't enough space to accommodate all your views at their natural size, it has to make a decision: one or more of those views needs to be squashed to make space for the others, but which one? That's where content compression resistance comes in: it's a value from 1 to 1000 that determines how happy you are for the view to be squashed if needed.
If you set a view's content compression resistance to be 1, it will be first in line to be squashed. If you set it to be 1000, it won't ever be squashed. The value is 750 by default, which means "I'd really prefer this not be squashed", but you might find you need to set it to be 751 or 749 on occasion, which means "I'd still really prefer this not to be squashed, but if there's no other choice…"
SPONSORED Ever ask for help and your reviewer immediately notices issues you missed? Fernando Olivares is a 10-year veteran from Big Nerd Ranch and Lambda School who can help hone your app building skills, and he's just launched a new book that does just that – use the code "hacking" to save $5!
Available from iOS 9.0
This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.
Link copied to your pasteboard.