코드로 view를 작성할 때엔 loadView() 메서드를 호출하여 유저 인터페이스를 생성하여 view를 초기화해 준 뒤 viewDidLoad()에서 추가 작업을 해야한다.
viewController의 lifeCycle
override func loadView() {
view = UIView()
view.backgroundColor = .white
}
NSLayoutConstraint.activate([
scoreLabel.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
scoreLabel.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor)
])
UIKit은 view를 고정할 수 있는 가이드를 여러 개 제공한다. safeAreaLayoutGuide와 layoutMarginsGuide가 가장 일반적으로 사용된다.
: 둥근 모서리와 노치를 제외한 사용 가능한 공간
: view가 왼쪽 및 오른쪽 가장자리에서 실행되지 않도록 여백을 추가한 공간
cluesLabel.setContentHuggingPriority(UILayoutPriority(1), for: .vertical)
answersLabel.setContentHuggingPriority(UILayoutPriority(1), for: .vertical)
그렇다면 지정해 주기 전에 default로 설정되어 있는 우선순위는 어떻게 될까?
위와 같이 UIView의 contenthuggingPriority를 찍어보니 vertical, horizontal 모두 250, 250 이 나온다.
객체마다 default로 지정되어 있는 우선순위 값이 다르다.