OGeek|极客世界-中国程序员成长平台

标题: ios - 自动布局以放置 4 个具有相同宽度的 View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:24
标题: ios - 自动布局以放置 4 个具有相同宽度的 View

enter image description here

我正在使用自动布局。我想将 View 高度设置为等于另一个 View 的宽度。棕色 View 的宽度设置为与其父 View 成比例的 0.3,绿色 View 的高度应与棕色 View 的宽度相同。 我已将约束设置为 4 个 View ,但 4 个 View 的宽度不一样

请引用图片。



Best Answer-推荐答案


Obj-c

NSLayoutConstraint *constraint = [NSLayoutConstraint
    constraintWithItem:greenView
    attribute:NSLayoutAttributeHeight
    relatedBy:NSLayoutRelationEqual
    toItem:brownView
    attribute:NSLayoutAttributeWidth
    multiplier: 1
    constant:0];

swift

 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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4