什么是默认的自动布局拥抱的内容和内容的COM pression性优先级值? [英] What are the default Auto Layout Content Hugging and Content Compression Resistance priority values?
问题描述
我试图调试自动布局问题,并且知道了拥抱的内容和内容的COM pression电阻的重点将帮助默认值。
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?
推荐答案
这些值均达到最新的为X code为7.3。
These values are up-to-date as of Xcode 7.3.
在拖动组件到界面生成器,你会得到如下的优先级。注:(250750)
为 250
水平和 750
垂直。
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 |
+-------------------------+---------------+------------------------------+
结果:
- 所有的对象都有
750750
作为内容的COM pression性优先级 - 大多数有
250,250
作为内容拥抱优先级 -
的UIImageView
和的UILabel
都有251251
作为他们的内容拥抱优先级 -
UIActivityIndicatorView
,UIStepper
和UISwitch
有750750
作为内容拥抱优先级 -
UIProgressView
的250750
为内容拥抱优先级
- All objects have
750,750
as their Content Compression Resistance Priority. - The majority have
250,250
as their Content Hugging Priority. UIImageView
andUILabel
both have251,251
as their Content Hugging Priority.UIActivityIndicatorView
,UIStepper
, andUISwitch
have750,750
as their Content Hugging Priority.UIProgressView
has250,750
as its Content Hugging Priority.
在编程方式创建一个对象(例如的UIButton()
),你会得到如下的优先级。
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 |
+-------------------------+---------------+------------------------------+
结果:
- 有内容拥抱优先级 IB之间的差异实例化对象和编程实例以下对象的对象:的UIDatePicker,UIImageView的,的UILabel,UIPageControl,UIPickerView,的UISearchBar,UISegmentedControl,UISlider,的UITabBar以及UIToolbar。
- 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.
+----------------------------------+-------+
| Constant | Value |
+----------------------------------+-------+
| UILayoutPriorityRequired | 1000 |
| UILayoutPriorityDefaultHigh | 750 |
| UILayoutPriorityDefaultLow | 250 |
| UILayoutPriorityFittingSizeLevel | 50 |
+----------------------------------+-------+
当您添加约束(通过界面生成器或编程),其默认的优先级为 1000
。
这篇关于什么是默认的自动布局拥抱的内容和内容的COM pression性优先级值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!