IOS 绘制imageView控件,以满足不规则imageView


- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];

    [[UIColor whiteColor] set];
    
    CGFloat radius = rect.size.width / 2;
    
    // 绘制路径
    //---------------------------------------------------------------------------------------------------------------------
    
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(radius, radius) radius:radius startAngle:M_PI endAngle:0 clockwise:YES];
    
    [path moveToPoint:CGPointMake(0, radius)];
    
    [path addQuadCurveToPoint:CGPointMake(radius, rect.size.height) controlPoint:CGPointMake(0, radius * 1.5)];
    
    [path addQuadCurveToPoint:CGPointMake(2 * radius, radius) controlPoint:CGPointMake(2 * radius, radius * 1.5)];
    
    // --------------------------------------------------------------------------------------------------------------------
    
    [path fill];
    
    [self.image drawAsPatternInRect:rect];
    
    CAShapeLayer *shapLayer = [CAShapeLayer layer];
    shapLayer.path = path.CGPath;
    self.layer.mask = shapLayer;
    
}


©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容