关键代码:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: view.bounds byRoundingCorners:UIRectCornerTopLeft cornerRadii:CGSizeMake(10, 10)];

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

maskLayer.frame = view.bounds;

maskLayer.path = maskPath.CGPath;

yearLabel.layer.mask = maskLayer;

弧形具体的方法如下:

UIRectCornerTopLeft //左上角弧形

UIRectCornerTopRight//右上角弧形

UIRectCornerBottomLeft//左下角弧形

UIRectCornerBottomRight//右下角弧形

若同时指定几个脚都有弧度用

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: view.bounds byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight |UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];

各个弧度之间用 | 隔开就好了

05-11 14:47