내일배움캠프 iOS

iOS) TIL #23 오토레이아웃 특강

yjuni22 2024. 11. 20. 23:00

AutoLayout(오토레이아웃)은 무엇인가 ?

https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/AutolayoutPG/index.html#//apple_ref/doc/uid/TP40010853-CH7-SW1

 

Auto Layout Guide: Understanding Auto Layout

 

developer.apple.com

 

Auto Layout은 iOS 앱에서 UI 요소(뷰)의 크기와 위치를 동적으로 정의하는 레이아웃 시스템입니다.

  • 화면 크기, 방향, 디바이스 종류(예: iPhone, iPad), 텍스트 길이, 콘텐츠 크기에 따라 뷰의 배치와 크기를 자동으로 조정
  • Auto Layout은 제약 조건(Constraints)을 사용해 뷰 간의 관계를 정의하며, iOS 앱 개발에서 다양한 디바이스와 다국어 지원을 위한 필수 기술
  • 내부 매커니즘 계산은 기본적으로 y = ax +c 꼴의 선형방정식을 따르고 있음; 부등식도 지원
  • 위치와 크기가 필수

 

SnapKit offset과 inset의 차이

결론부터 말하면

  • offset → NSLayoutContraint 사용
  • inset → UIEdgeInsets 인스턴스를 생성해서 사용; NSLayoutContraint 사용 UIEdgeInsets는 간략하게 설명하자면, 양수 사용시 축소가 됨(padding의 역할)