IOS设置按钮为圆角的方法
来源:爱站网时间:2021-02-26编辑:网友分享
我们在ios系统中经常使用到指定风格的圆角按钮,但是也有很多用户们不知道怎么设置圆角按钮,那么接下来的内容中我们就一起去看看IOS设置按钮为圆角的方法。
我们在ios系统中经常使用到指定风格的圆角按钮,但是也有很多用户们不知道怎么设置圆角按钮,那么接下来的内容中我们就一起去看看IOS设置按钮为圆角的方法。
设置按钮的4个角:
左上:UIRectCornerTopLeft
左下:UIRectCornerBottomLeft
右上:UIRectCornerTopRight
右下:UIRectCornerBottomRight
示例代码:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 60, 80, 40)]; button.backgroundColor = [UIColor orangeColor]; [self.view addSubview:button]; //这里设置的是左上和左下角 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(8, 8)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = button.bounds; maskLayer.path = maskPath.CGPath; button.layer.mask = maskLayer;
效果图
以上关于IOS设置按钮为圆角的方法,大家都学会了吗?希望这篇文章对大家的开发能有一定的帮助,如果有疑问大家可以留言交流。