4 개의 버튼 레이아웃이 있습니다. 세로로 보면 서로 위에 하나씩 표시해야합니다. 가로 방향에서는 두 개의 열이 있고 두 개의 버튼이 있어야합니다.크기 클래스를 사용하여 프로그래밍 방식으로 두 개의 다른 레이아웃 구현
나는 코드에서 버튼을 구현 - 정말 간단한 물건을 :
UIButton *btn1 = [[UIButton alloc] init];
[self.view addSubview: btn1];
UIButton *btn2 = [[UIButton alloc] init];
[self.view addSubview: btn2];
UIButton *btn3 = [[UIButton alloc] init];
[self.view addSubview: btn3];
UIButton *btn4 = [[UIButton alloc] init];
[self.view addSubview: btn4];
NSDictionary *views = NSDictionaryOfVariableBindings(btn1, btn2, btn3, btn4);
[btn1 setTranslatesAutoresizingMaskIntoConstraints:NO];
[btn2 setTranslatesAutoresizingMaskIntoConstraints:NO];
[btn3 setTranslatesAutoresizingMaskIntoConstraints:NO];
[btn4 setTranslatesAutoresizingMaskIntoConstraints:NO];
// portrait constraints
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(50)-[btn1]-(50)-|"
options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(50)-[btn2]-(50)-|"
options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(50)-[btn3]-(50)-|"
options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(50)-[btn4]-(50)-|"
options:0 metrics:nil views:views]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[btn1]-[btn2]-[btn3]-[btn4]-(50)-|"
options:0 metrics:nil views:views]];
이 분명 세로 레이아웃에 대한 설정입니다. 나는 각각의 방향에서 iPad와 iPhone을위한 특별한 경우를 만들기 위해 장치와 방향을 결정하는 데 익숙했습니다. 그러나 이제 우리는 크기 클래스를 사용하기로되어 있습니다. 크기 클래스가 "컴팩트"한지 어떻게 알 수 있습니까? 그러면 적절한 제약 조건을 설정할 수 있습니까?
ummm wwdc 세션이이게 뭐야? – Honey