今天項(xiàng)目提出一個(gè)新需求,需要將一個(gè)label
右邊切圓角,左邊不切,實(shí)現(xiàn)了以下,共享一下代碼.
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];