我UIView在.xib文件中定义了一个.我需要设置translatesAutoresizingMaskIntoConstraints = NO.这意味着框架没有转换为约束,所以我需要自己设置大小约束.
我为a创建了一个工作类别方法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];
}
Run Code Online (Sandbox Code Playgroud)
但我想从Xcode界面构建器设置这些约束,但我的所有AutoLayout控件都是灰色的:

有没有办法在界面构建器中执行此操作?