【问题标题】:What are the default Auto Layout Content Hugging and Content Compression Resistance priority values?默认的 Auto Layout Content Hugging 和 Content Compression Resistance 优先级值是多少?
【发布时间】:2016-08-23 18:34:42
【问题描述】:

我正在尝试调试自动布局问题,知道内容拥抱和内容压缩阻力优先级的默认值会有所帮助。

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

关键字:UILayoutPriority

【问题讨论】:

    标签: ios autolayout interface-builder


    【解决方案1】:

    这些值在 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
    • UIImageViewUILabel 都将 251,251 作为他们的Content Hugging Priority
    • UIActivityIndicatorViewUIStepperUISwitch750,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 实例化对象和编程实例化对象之间存在 Content Hugging Priority 差异:UIDatePicker、UIImageView、UILabel、UIPageControl、UIPickerView、UISearchBar、UISegmentedControl、UISlider、UITabBar 和 UIToolbar。

    程序常量

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

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

    【讨论】:

    • 这个超级有用,不敢相信Apple没有记录这个,尤其是IB和代码内初始化对象的区别
    猜你喜欢
    • 2020-10-02
    • 2013-03-30
    • 1970-01-01
    • 2015-03-03
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多