iOS Xib 设置控件的圆角和边框

如下图:找到xib工具别表里的User Defind RunTime Attributes,点击“+”添加属性

 1.设置圆角:

layer.cornerRadius, Type为String或者Number都可以

layer.masksToBounds ,(这里注意:UIButton、UIView、UIImageView可以不写这句,但是Lbale一定要写)

其对应的代码分别为:

UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 100, 50)];
btn.layer.cornerRadius = 25;
btn.clipsToBounds = YES;

2.设置边框:

layer.borderWidth,Type为String或者Number都可以

layer.borderColorWithUIColor,Type为Color类型

其对应的代码为:

 btn.layer.borderWidth = 1.0;
 btn.layer.borderColor = [UIColor redColor].CGColor;

注意⚠️,在Xib设置的圆角和边框,并不能指甲在xib上看到效果,只有运行之后在模拟器或者手机上才能看到效果

猜你喜欢

转载自blog.csdn.net/wyz670083956/article/details/129621658