Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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? Are they specific to particular components? Are there constants I can use to refer to them?

Keywords: UILayoutPriority

like image 350
Senseful Avatar asked Apr 28 '16 19:04

Senseful


1 Answers

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.

like image 180
Senseful Avatar answered Oct 17 '22 02:10

Senseful