frame 설정을 통해 View의 위치와 크기를 수동으로 결정 View의 위치나 크기를 다른 객체에 상대적으로 제약(Constraint)을 줘서 배치
사용 가능한 Attribute:
leading, trailing, left, right, top, bottomcenterX, centerY, center, width, heightleading: 왼쪽
trailing: 오른쪽
translatesAutoresizingMaskIntoConstraints = false 로 설정해야 Autolayout 적용 가능 .flexibleRightMargin.flexibleLeftMargin: 왼쪽이 유연하게 변화 .flexibleWidth, .flexibleHeight: 부모 크기에 맞게 동적으로 변화 true일 경우 AutoresizingMask와 Constraint가 충돌해서 Auto Layout 비활성화됨| View Type | Width | Height |
|---|---|---|
| UIView | ❌ | ❌ |
| UISlider | ✅ | ❌ |
| UILabel, UIButton, UISwitch, UITextField | ✅ | ✅ |
| UITextView, UIImageView | 콘텐츠에 따라 결정됨 |
invalidateIntrinsicContentSize()setContentHuggingPriority(_:for:) View가 줄어들지 않도록 하는 우선순위
"나 안 줄어들고 싶어"
시스템 기본값:
.defaultLow: 250.defaultHigh: 750.required: 1000leftLabel.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.3)
rightLabel.widthAnchor.constraint(equalTo: container.widthAnchor, multiplier: 0.7)