layer设置指定圆角 或者设定一个或几个圆角

2017-04-20  本文已影响294人  码修

由于项目中需要给按钮左下 和左上加圆角,我司可爱的ui君并不想给我切图。
所以只有自己画了。由于很久没有用过这些知识,花了一些时间,
故记入笔记。
也可以用来画半圆。
选择要画圆角的位置只需要改变枚举即可。
有空能封装一下更好。

WX20170420-190022@2x.png
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.statusLabel.bounds
                                                   byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft
                                                         cornerRadii:CGSizeMake(self.statusLabel.height/2, self.statusLabel.height/2)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.statusLabel.bounds;
    maskLayer.path = maskPath.CGPath;
    self.statusLabel.layer.mask = maskLayer;

上一篇 下一篇

猜你喜欢

热点阅读