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;
    
}


你可能感兴趣的:(IOS 绘制imageView控件,以满足不规则imageView)