控件的局部圆角问题
这种情况需要用图层蒙版来解决,凡是继承自UIView的控件都可以使用这种方法,以UIButton为例:
UIButton *button = [[UIButton alloc] init];
CGRect rect = CGRectMake(0, 0, 100, 50);
//圆角尺寸
CGSize radio = CGSizeMake(5, 5);
//圆角的位置
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
//创建ShapeLayer
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = button.bounds;
//设置路径
maskLayer.path = path.CGPath;
button.layer.mask = maskLayer;