如何使用贝塞尔曲线设置圆角

给控件画圆角的方法有很多,今天我们就介绍一下怎样用使用CAShapeLayer和UIBezierPath设置圆角。

#define SWidth [UIScreen mainScreen].bounds.size.width

#define SHeight [UIScreen mainScreen].bounds.size.height

UIButton *playBtn = [UIButton buttonWithType:UIButtonTypeCustom];

[self addSubview:playBtn];

playBtn.frame = CGRectMake((SWidth - 100) / 2, (SHeight - 50) / 2, 100, 50);

UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:_playBtn.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(10, 10)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

maskLayer.frame = playBtn.bounds;

maskLayer.path = maskPath.CGPath;

playBtn.layer.mask = maskLayer;

[playBtn setTitle:@"视频" forState:UIControlStateNormal];

playBtn.backgroundColor = [UIColor blueColor];

使用这种方法设置圆角,对内存的消耗最少,而且渲染快速。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容