例如给一个view加圆角:
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
CGFloat corner = 6;
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(corner, corner)].CGPath;
view.layer.mask = shapeLayer;
网友评论