ฉันกำลังพยายามแทนที่ set frame ด้วยข้อจำกัดสำหรับ UIButton แต่โค้ดของฉันยังคงขัดข้อง ฉันทำอะไรผิด
- (void)CreateButton {
self.Button = [[UIButton alloc] init];
//self.Button.frame = CGRectMake(30, 30, 100, 100);
[self.Button addConstraint:[NSLayoutConstraint constraintWithItem:MyScrollView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.myButton
attribute:NSLayoutAttributeTop
multiplier:2.0
constant:30]];
[self.myButton addConstraint:[NSLayoutConstraint constraintWithItem:MyScrollView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:self.myButton
attribute:NSLayoutAttributeHeight
multiplier:3.0
constant:50]];
[self.myButton setBackgroundColor:[UIColor orangeColor]];
[self.myButton setTitle:@"Press Me" forState:UIControlStateNormal];
[self.myButton setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
[MyScrollView addSubview:self.myButton];
self.myButton.view.translatesAutoresizingMaskIntoConstraints = NO;
ก่อนที่จะเพิ่มข้อจำกัด - person AnthonyR   schedule 26.05.2016self.myButton
แทนที่จะเป็นself.Button
ที่ตอนต้นของโค้ดของคุณ - person AnthonyR   schedule 26.05.2016