What are the default Auto Layout Content Hugging and Content Compression Resistance priority values?

前端 未结 1 945
不思量自难忘°
不思量自难忘° 2021-01-31 06:05

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? A

相关标签:
1条回答
  • 2021-01-31 06:29

    These values are up-to-date as of Xcode 7.3.


    Interface Builder Default Priority Values:

    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:

    • All objects have 750,750 as their Content Compression Resistance Priority.
    • The majority have 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.

    Programmatic Default Priority Values:

    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:

    • There are Content Hugging Priority differences between IB instantiated objects and programmatically instantiated objects for the following objects: UIDatePicker, UIImageView, UILabel, UIPageControl, UIPickerView, UISearchBar, UISegmentedControl, UISlider, UITabBar, and UIToolbar.

    Programmatic Constants

    +----------------------------------+-------+
    |             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.

    0 讨论(0)
提交回复
热议问题