今天项目提出一个新需求,需要将一个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];
效果图
网友评论