In the docs https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html关于视觉格式语言NSLayoutConstraint
有一个示例,您指定按钮 1 的宽度等于按钮 2 的宽度:
[button1(==button2)]
我的问题:有没有办法让按钮 1 等于按钮 2 的 + 常量..我尝试过:
[button1(==button2+10)]
and
[button1(==(button2+10))]
两者都失败了..这是一个错误示例:
A predicate on a view's thickness must end with ')' and the view must end with ']'
V:[tagWrapper(==tagButton+10)]
^'
(我显然知道你可以通过执行 NSStringWithFormat 并简单地填写有问题的变量来做到这一点......但这看起来太混乱了)
ideas?
附:以防万一您好奇为什么我想坚持使用视觉格式语言(而不是其他方式,例如this https://stackoverflow.com/a/20019764/766570回答..或使用包装库 https://github.com/smileyborg/UIView-AutoLayout在那里..看看this https://gist.github.com/abbood/7500976代码示例)
某些约束无法使用视觉格式语言指定。您可以使用这样的简单约束:
NSLayoutConstraint *c;
c = [NSLayoutConstraint constraintWithItem:button1
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:button2
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:10.0];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)