16
我有一个label
和button
在这样一个superView
。增加布局约束的优先级
|--------------[Label]-----[button]-|
我想要label
是centred
如果可能的话,那么有差距最小的button
并移动到左边。
因此,如果按钮是大的,它看起来像......
|-[ LABEL! ]-[button]-|
所以,按钮停留的地方是,在相同的尺寸。元素之间有最小的差距。
我可以添加centerX
约束,但我似乎无法给它一个优先级,所以它仍然Required
。
我该如何创建这种情况?我正在做代码中的所有自动布局。
我现在有是约束...
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-[_label]-(>[email protected])-[_button(==45)]-|"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:views]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:_label
attribute:NSLayoutAttributeCenterX
relatedBy:NSLayoutRelationEqual
toItem:self.contentView
attribute:NSLayoutAttributeCenterX
multiplier:1.0
constant:0.0]];
但我不知道如何降低第二约束的优先级。
当然!谢谢!我没想过在添加它之前创建对象。完善!现在排序,谢谢! – Fogmeister 2013-03-12 15:35:41