UILabel切圆角,另一半不切圆角

今天项目提出一个新需求,需要将一个label右边切圆角,左边不切,实现了以下,共享一下代码.

UILabel * JHLabel = [[UILabel alloc]initWithFrame:CGRectMake(60, 60, 160 , 60)];

JHLabel.backgroundColor = [UIColor lightGrayColor];
JHLabel.textAlignment = NSTextAlignmentCenter;
JHLabel.textColor = [UIColor whiteColor];
JHLabel.text = @"121212";
// JHLabel.layer.masksToBounds = YES;
// JHLabel.layer.cornerRadius = 10;
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:JHLabel.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(30, 30)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = JHLabel.bounds;
maskLayer.path = maskPath.CGPath;
JHLabel.layer.mask  = maskLayer;
[self.view addSubview:JHLabel];
UILabel切圆角,另一半不切圆角_第1张图片
效果图

你可能感兴趣的:(UILabel切圆角,另一半不切圆角)