以UILabel举例,效果图如下:
代码如下:
//设置左上与右下圆角(可自行编辑指定圆角位置)
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_sleepStateLabel.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(12, 12)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = _sleepStateLabel.bounds;
maskLayer.path = maskPath.CGPath;
_sleepStateLabel.layer.mask = maskLayer;