【发布时间】:2016-08-23 18:34:42
【问题描述】:
我正在尝试调试自动布局问题,知道内容拥抱和内容压缩阻力优先级的默认值会有所帮助。
它们是什么?它们是否特定于特定组件?有没有我可以用来引用它们的常量?
关键字:UILayoutPriority
【问题讨论】:
标签: ios autolayout interface-builder
我正在尝试调试自动布局问题,知道内容拥抱和内容压缩阻力优先级的默认值会有所帮助。
它们是什么?它们是否特定于特定组件?有没有我可以用来引用它们的常量?
关键字:UILayoutPriority
【问题讨论】:
标签: ios autolayout interface-builder
这些值在 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 作为他们的Content Hugging Priority。UIImageView 和 UILabel 都将 251,251 作为他们的Content Hugging Priority。UIActivityIndicatorView、UIStepper 和 UISwitch 将 750,750 作为他们的Content Hugging Priority。UIProgressView 将 250,750 作为其Content Hugging Priority。以编程方式创建对象时(例如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 |
+-------------------------+---------------+------------------------------+
调查结果:
+----------------------------------+-------+
| Constant | Value |
+----------------------------------+-------+
| UILayoutPriorityRequired | 1000 |
| UILayoutPriorityDefaultHigh | 750 |
| UILayoutPriorityDefaultLow | 250 |
| UILayoutPriorityFittingSizeLevel | 50 |
+----------------------------------+-------+
当您添加约束时(通过 Interface Builder 或以编程方式),其默认优先级为 1000。
【讨论】: