I'm trying to debug an Auto Layout problem, and knowing the default values for Content Hugging and Content Compression Resistance priorities will help.
What are they? Are they specific to particular components? Are there constants I can use to refer to them?
Keywords: UILayoutPriority
These values are up-to-date as of Xcode 7.3.
When dragging a component into Interface Builder, you get the following priorities. Note: (250,750)
stands for 250
horizontal, and 750
vertical.
+-------------------------+---------------+------------------------------+
| Object | Hugging (H,V) | Compression Resistance (H,V) |
+-------------------------+---------------+------------------------------+
| UIActivityIndicatorView | 750,750 | 750,750 |
| UIButton | 250,250 | 750,750 |
| UIDatePicker | 250,250 | 750,750 |
| UIImageView | 251,251 | 750,750 |
| UILabel | 251,251 | 750,750 |
| UIPageControl | 250,250 | 750,750 |
| UIPickerView | 250,250 | 750,750 |
| UIProgressView | 250,750 | 750,750 |
| UIScrollView | 250,250 | 750,750 |
| UISearchBar | 250,250 | 750,750 |
| UISegmentedControl | 250,250 | 750,750 |
| UISlider | 250,250 | 750,750 |
| UIStepper | 750,750 | 750,750 |
| UISwitch | 750,750 | 750,750 |
| UITabBar | 250,250 | 750,750 |
| UITextField | 250,250 | 750,750 |
| UITextView | 250,250 | 750,750 |
| UIToolbar | 250,250 | 750,750 |
| UIView | 250,250 | 750,750 |
+-------------------------+---------------+------------------------------+
Findings:
750,750
as their Content Compression Resistance Priority.250,250
as their Content Hugging Priority.UIImageView
and UILabel
both have 251,251
as their Content Hugging Priority.UIActivityIndicatorView
, UIStepper
, and UISwitch
have 750,750
as their Content Hugging Priority.UIProgressView
has 250,750
as its Content Hugging Priority.When creating an object programmatically (e.g. UIButton()
), you get the following priorities.
+-------------------------+---------------+------------------------------+
| Object | Hugging (H,V) | Compression Resistance (H,V) |
+-------------------------+---------------+------------------------------+
| UIActivityIndicatorView | 750,750 | 750,750 |
| UIButton | 250,250 | 750,750 |
| UIDatePicker | 750,750 | 750,750 |
| UIImageView | 250,250 | 750,750 |
| UILabel | 250,250 | 750,750 |
| UIPageControl | 750,750 | 750,750 |
| UIPickerView | 750,750 | 750,750 |
| UIProgressView | 250,750 | 750,750 |
| UIScrollView | 250,250 | 750,750 |
| UISearchBar | 250,750 | 750,750 |
| UISegmentedControl | 250,750 | 750,750 |
| UISlider | 250,750 | 750,750 |
| UIStepper | 750,750 | 750,750 |
| UISwitch | 750,750 | 750,750 |
| UITabBar | 250,750 | 750,750 |
| UITextField | 250,250 | 750,750 |
| UITextView | 250,250 | 750,750 |
| UIToolbar | 250,750 | 750,750 |
| UIView | 250,250 | 750,750 |
+-------------------------+---------------+------------------------------+
Findings:
+----------------------------------+-------+
| Constant | Value |
+----------------------------------+-------+
| UILayoutPriorityRequired | 1000 |
| UILayoutPriorityDefaultHigh | 750 |
| UILayoutPriorityDefaultLow | 250 |
| UILayoutPriorityFittingSizeLevel | 50 |
+----------------------------------+-------+
When you add a constraint (either via Interface Builder or programmatically), its default priority is 1000
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With