iOS View指定圆某个角

在开发中会遇到需要一个View只圆某个角,例如指定上方两个的角进行圆角处理,方法如下:

 UILabel * exChangeLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, self.view.width-10 , 20)]; 
 exChangeLabel.backgroundColor = setColor(0, 0, 0, 0.8); 
 exChangeLabel.textAlignment = NSTextAlignmentCenter; 
 exChangeLabel.textColor = [UIColor whiteColor]; 
 // exChangeLabel.layer.masksToBounds = YES;
 // exChangeLabel.layer.cornerRadius = 10; 
 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:exChangeLabel.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(7, 7)];
 CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
 maskLayer.frame = exChangeLabel.bounds;
 maskLayer.path = maskPath.CGPath;
 exChangeLabel.layer.mask = maskLayer;

你可能感兴趣的:(iOS View指定圆某个角)