티스토리 뷰
iOS
[iOS 오토레이아웃 Views with Intrinsic Content Size] Two Equal - Width Buttons
rhinoPHS 2018. 8. 2. 15:32from apple auto layout guide
[iOS 오토레이아웃 Views with Intrinsic Content Size] Two Equal - Width Buttons
width가 같은 두 개의 버튼을 만드는 예제입니다. 전에 했던 예제에 비해 간단합니다.
width Intrinsic Content Size를 고려하지 않아서 별로 좋지 않은 예제라고 생각됩니다. 그래서 예제로 넣었을 수 도 있겠습니다.
View and Constraints
Short Button.Leading = Safe Area.leading + 16
Long Button.Leading = Short Button.Trailing + Standard
Long Button.Trailing = Safe Area.Trailing + 16
Bottom Layout Guide.Top = Short Button.Bottom + 20.0
Bottom Layout Guide.Top = Long Button.Botton + 20.0
Short Button.Width = Long Button.Width
Atrributes
button의 타이틀을 바꿔주시고, button의 크기를 보기 쉽게 button의 배경색을 줍니다.
Discussion
button에는 intrinsic content size가 있습니다. width는 고려하지 않지만 height는 고려합니다. 그래서 4,5번 두 개만 필요한 것이죠. 아래 글에서는 intrinsic content size가 없는 view를 가지고 했기 때문에 위아래 4개 필요했습니다. 비교하면 intrinsic content size가 어떻게 레이아웃에 영향을 끼치는지 알 수 있습니다.