CGRect rect = CGRectMake(100, 100, 150, 250);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:rect];
imageView.image = [UIImage imageNamed:@"brand_launch"];
[self.view addSubview:imageView];
CAShapeLayer *layer = [CAShapeLayer layer];
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 15)];
[path addLineToPoint:CGPointMake(15, 15)];
[path addArcWithCenter:CGPointMake(15+5, 5) radius:5 startAngle:M_PI endAngle:1.5*M_PI clockwise:YES];
[path addArcWithCenter:CGPointMake(150-5, 5) radius:5 startAngle:1.5*M_PI endAngle:2*M_PI clockwise:YES];
[path addArcWithCenter:CGPointMake(150-5, 250-5) radius:5 startAngle:0 endAngle:M_PI_2 clockwise:YES];
[path addArcWithCenter:CGPointMake(15+5, 250-5) radius:5 startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
[path addLineToPoint:CGPointMake(15, 30)];
[path closePath];
layer.path = path.CGPath;
imageView.layer.mask = layer;
"思路: 如果想应用在多种图片格式上? "
我可能会考虑把这个圆角放到一个UIView上,
然后通过重写View的LayoutSubviews方法来实时取到正确的view的宽高, 来实现绘制
各人按需求封装一下吧