ios Object-C mas_makeConstraints 设置圆角
在iOS中,可以使用mas_makeConstraints方法来设置圆角。具体步骤如下:
-
导入
Masonry头文件:#import <Masonry/Masonry.h> -
创建要设置圆角的视图对象,例如一个
UIView对象:UIView *myView = [[UIView alloc] init]; -
设置视图的圆角属性:
myView.layer.cornerRadius = 10.0; -
将视图添加到父视图中:
[self.view addSubview:myView]; -
使用
mas_makeConstraints方法设置视图的约束:[myView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(20, 20, 20, 20)); }]; -
注:
make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(20, 20, 20, 20))将视图的边缘与父视图的边缘保持20的间距。
完整代码示例:
#import <Masonry/Masonry.h>
UIView *myView = [[UIView alloc] init];
myView.layer.cornerRadius = 10.0;
[self.view addSubview:myView];
[myView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(20, 20, 20, 20));
}];
通过以上步骤,就可以使用mas_makeConstraints方法设置圆角
原文地址: https://www.cveoy.top/t/topic/ix0b 著作权归作者所有。请勿转载和采集!