iOS UILabel 上方两边加圆角

 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 UILabel 上方两边加圆角)