我有一个UIView
在 .xib 文件中定义。我需要设置translatesAutoresizingMaskIntoConstraints = NO
。这意味着框架不会转换为约束,因此我需要自己设置尺寸约束。
我创建了一个工作类别方法UIView
:
-(NSArray*)setSizeConstraints:(CGSize)size
{
NSLayoutConstraint* height = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeHeight relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:size.height];
NSLayoutConstraint* width = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeWidth relatedBy:0 toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:size.width];
[self addConstraint:height];
[self addConstraint:width];
return [NSArray arrayWithObjects:height, width, nil];
}
But I would like to set these constraints from the Xcode interface builder, but all my AutoLayout controls are greyed out:
有没有办法在界面生成器中执行此操作?
这实际上是可能的。
Simply put the view you'd like to constrain into another view, like the highlighted view here.
然后,添加您想要的约束。
最后,拉出刚刚添加约束的视图out其父视图。您现在可以向该视图添加约束。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)