【发布时间】:2013-07-05 06:26:25
【问题描述】:
如何在 constraintsWithVisualFormat 中同时添加水平和垂直视觉格式?只有水平的。我想添加 V:|-50-[leftButton] 和 V:|-50-[rightButton] 到它。怎么做?创建另一个 NSLayoutConstraint?
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[leftButton setTitle:@"Left" forState:UIControlStateNormal];
[leftButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:leftButton];
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[rightButton setTitle:@"Right" forState:UIControlStateNormal];
[rightButton setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:rightButton];
NSArray *layoutConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[leftButton(>=80)]-50-[rightButton(>=80)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(leftButton, rightButton)];
[self.view addConstraints:layoutConstraints];
}
【问题讨论】:
-
把它和图片放在一起,然后解释你想要什么......它可以更好地理解:)
-
@iPatel 我自己回答了。告诉我这是否是这样做的方式。
标签: iphone ios constraints autolayout