在開(kāi)發(fā)中會(huì)遇到需要一個(gè)View只圓某個(gè)角,例如指定上方兩個(gè)的角進(jìn)行圓角處理丰榴,方法如下:
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;