作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图将我的 View 顶部约束(y 值)设置为父 View 高度的百分比(乘数)。我需要使用引用而不是值约束来解释设备旋转。
我在非自动布局中尝试的等效内容如下:
[self.labelView setFrame:CGRectMake(0, self.frame.size.height * 0.8, self.frame.size.width, 20)];
我想要实现的是将 View 的 TOP 约束设置为父 View 高度的 80%,如下所示:
[self.labelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_height).multipliedBy(0.8);
make.left.and.right.equalTo(self.contentView);
make.height.equalTo(20);
}];
但是,这种方法行不通。 Masonry 库可以做到这一点吗?
最佳答案
使用 contentView.mas_bottom
代替 contentView.mas_height
,尝试设置 labelView.top
或 labelView.bottom
约束,我认为两者应该产生相同的结果:
[labelView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.contentView.mas_bottom).multipliedBy(0.8);
make.left.and.right.equalTo(self.contentView);
make.height.equalTo(@20);
}];
Swift 等价物
labelView.mas_makeConstraints { (make:MASConstraintMaker!) in
make.bottom.equalTo()(self.contentView.mas_bottom)!.multipliedBy()(0.8)
make.left.and().right().mas_equalTo()(self.contentView)
make.height.mas_equalTo()(20.0)
}
关于ios - 将砌体 x/y 约束设置为 View 宽度/高度的百分比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56138348/
我是一名优秀的程序员,十分优秀!