view.layer.cornerRadius = 3.f;
// 不用写
view.layer.masksToBounds = YES;
view.clipToBounds = YES;
@implementation UIImage (extend)
- (UIImage *)drawRectWithRoundedCorner
{
CGRect rect = CGRectMake(0.f, 0.f, 150.f, 150.f);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:rect.size.width * 0.5];
UIGraphicsBeginImageContextWithOptions(rect.size, false, [UIScreen mainScreen].scale);
CGContextAddPath(UIGraphicsGetCurrentContext(), bezierPath.CGPath);
CGContextClip(UIGraphicsGetCurrentContext());
[self drawInRect:rect];
CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathFillStroke);
UIImage *output = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return output;
}
@end
网友评论