我正在使用自动版式。我想将一个视图的高度设置为等于另一个视图的宽度。棕色视图的宽度设置为与其父视图成比例的0.3,绿色视图的高度应与棕色视图的宽度相同。
我已经将约束设置为4个视图,但是4个视图的宽度不一样
请参考图片。
最佳答案
对象
NSLayoutConstraint *constraint = [NSLayoutConstraint
constraintWithItem:greenView
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:brownView
attribute:NSLayoutAttributeWidth
multiplier: 1
constant:0];
迅捷
NSLayoutConstraint(item: greenView,
attribute: .Height,
relatedBy: .Equal,
toItem: brownView,
attribute: .Width,
multiplier: 1,
constant: 0.0);
我没有测试代码,所以请告诉我是否有问题
关于ios - 自动布局以相同宽度放置4个 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39204245/