gpt4 book ai didi

ios - 默认的 Auto Layout Content Hugging 和 Content Compression Resistance 优先级值是多少?

转载 作者:可可西里 更新时间:2023-11-01 03:02:09 25 4
gpt4 key购买 nike

我正在尝试调试自动布局问题,了解 Content Hugging 和 Content Compression Resistance 优先级的默认值会有所帮助。

它们是什么?它们是否特定于特定组件?我可以使用常量来引用它们吗?

关键词:UILayoutPriority

最佳答案

从 Xcode 7.3 开始,这些值是最新的。


Interface Builder 默认优先级值:

将组件拖入 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 作为它们的Content Compression Resistance Priority
  • 大多数人将 250,250 作为他们的Content Hugging Priority
  • UIImageViewUILabel 都将 251,251 作为它们的Content Hugging Priority
  • UIActivityIndi​​catorViewUIStepperUISwitch750,750 作为它们的Content Hugging Priority.
  • UIProgressView250,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 |
+-------------------------+---------------+------------------------------+

调查结果:

  • 对于以下对象,IB 实例化对象和以编程方式实例化的对象之间存在内容拥抱优先级差异:UIDatePicker、UIImageView、UILabel、UIPageControl、UIPickerView、UISearchBar、UISegmentedControl、UISlider、UITabBar 和 UIToolbar。

程序常量

+----------------------------------+-------+
| Constant | Value |
+----------------------------------+-------+
| UILayoutPriorityRequired | 1000 |
| UILayoutPriorityDefaultHigh | 750 |
| UILayoutPriorityDefaultLow | 250 |
| UILayoutPriorityFittingSizeLevel | 50 |
+----------------------------------+-------+

当您添加约束(通过 Interface Builder 或以编程方式)时,其默认优先级为 1000

关于ios - 默认的 Auto Layout Content Hugging 和 Content Compression Resistance 优先级值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36924093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com