我正在尝试调试自动布局问题,并且知道内容拥抱和内容压缩阻力优先级的默认值会有所帮助。
他们是什么?它们是否特定于特定组件?我可以使用常量来引用它们吗?
关键字:UILayoutPriority
答案 0 :(得分:29)
从Xcode 7.3开始,这些值是最新的。
将组件拖动到Interface Builder中时,您将获得以下优先级。注意:(250,750)
代表250
水平,750
垂直。
+-------------------------+---------------+------------------------------+
| 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 |
+-------------------------+---------------+------------------------------+
调查结果:
750,750
。250,250
作为内容拥抱优先级。UIImageView
和UILabel
都有251,251
作为内容拥抱优先级。UIActivityIndicatorView
,UIStepper
和UISwitch
将750,750
作为内容拥抱优先级。UIProgressView
已将{{1>}作为其内容拥抱优先级。以编程方式创建对象(例如250,750
)时,您将获得以下优先级。
UIButton()
调查结果:
+-------------------------+---------------+------------------------------+
| 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 |
+-------------------------+---------------+------------------------------+
添加约束时(通过Interface Builder或以编程方式),其默认优先级为+----------------------------------+-------+
| Constant | Value |
+----------------------------------+-------+
| UILayoutPriorityRequired | 1000 |
| UILayoutPriorityDefaultHigh | 750 |
| UILayoutPriorityDefaultLow | 250 |
| UILayoutPriorityFittingSizeLevel | 50 |
+----------------------------------+-------+
。