设置圆角

1.layer层设置

 
 
self.myButton = [[UIButton alloc] initWithFrame:self.bounds];
self.myButton.layer.cornerRadius = (self.myButton.frame.size.width - 1) / 2;//圆形
self.myButton.clipsToBounds = true;
(self.myButton.layer.masksToBounds = YES;)
//设置边框及其颜色
self.myButton.layer.borderWidth = 1.0;
self.myButton.layer.borderColor = [[UIColor whiteColor] CGColor];

2.storyboard 语句备注

layer.masksToBounds

layer.cornerRadius

3.使用CAShapeLayer和UIBezierPath设置圆角

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.myButton.bounds byRoundingCorners:UIRectCornerAllCorners  cornerRadii:CGSizeMake(25, 5)];//byRoundingCorners可以设置左上圆角,右上圆角等:UIRectCornerBottomLeft | UIRectCornerTopLeft
CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
maskLayer.frame = self.myButton.bounds;
maskLayer.path = maskPath.CGPath;
self.myButton.layer.mask = maskLayer;

猜你喜欢

转载自blog.csdn.net/weixin_42045633/article/details/80048091
今日推荐