uiview的4个角中某几个角变成圆角

使用

+ (UIBezierPath *)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii(ios 3.2 and later)

enum {

   UIRectCornerTopLeft     = 1 << 0,

   UIRectCornerTopRight    = 1 << 1,

   UIRectCornerBottomLeft  = 1 << 2,

   UIRectCornerBottomRight = 1 << 3,

   UIRectCornerAllCorners  = ~0

};

 

typedef NSUInteger UIRectCorner;

以及CAShapeLayer来实现.

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerBottomLeft cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *maskLayer = [CAShapeLayer layer]; 

maskLayer.frame = targetView.bounds; 

maskLayer.path = maskPath.CGPath;

targetView.layer.mask = maskLayer;

你可能感兴趣的:(iOS)