如何通过包含另一个button的宽度加一个常量来编写NSConstraint可视化格式语言
在关于NSLayoutConstraint
的可视化格式语言的NSLayoutConstraint
有一个例子,您指定button1的宽度与button2相等:
[button1(==button2)]
我的问题:有没有办法让button1等于button2的+常量..我试过:
[button1(==button2+10)]
和
[button1(==(button2+10))]
和两个失败..这里是一个错误的例子:
A predicate on a view's thickness must end with ')' and the view must end with ']' V:[tagWrapper(==tagButton+10)] ^'
(我明显知道你可以通过做一个NSStringWithFormat来做到这一点,只需填写问题的variables..但看起来太乱了)
想法?
PS以防万一你好奇为什么我想坚持视觉格式语言(而不是像这样做的答案..或使用包装库在那里..检查出这个代码示例)
可视格式语言不能指定一些约束条件。 你可以使用这样一个简单的约束:
NSLayoutConstraint *c; c = [NSLayoutConstraint constraintWithItem:button1 attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:button2 attribute:NSLayoutAttributeWidth multiplier:1.0 constant:10.0];