iOS 控件切圆角 任意角

使用前提是不能使用mansory 得使用frame布局!

1.如果是切四个角的圆角,代码示例:

imgView.layer.cornerRadius = 8;

imgView.layer.masksToBounds = YES;

2.如果是四个角中的某几个角,一个,两个,或者3个,代码示例(切的左下,和右下):

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.tipLabel.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

maskLayer.frame = _tipLabel.bounds;

maskLayer.path = maskPath.CGPath;

self.tipLabel.layer.mask = maskLayer;

==================================

类型共有以下几种:

* UIRectCornerTopLeft  //左上

* UIRectCornerTopRight  //右上

* UIRectCornerBottomLeft  //左下

* UIRectCornerBottomRight  //右下

* UIRectCornerAllCorners  //所有

你可能感兴趣的:(iOS 控件切圆角 任意角)