`
1021082712
  • 浏览: 84391 次
  • 性别: Icon_minigender_2
  • 来自: 武汉
社区版块
存档分类
最新评论

利用CGContextClip、CGPathAddEllipseInRect裁剪视图

    博客分类:
  • ios
阅读更多

 

以下可讲视图裁剪成一个圆形或椭圆:

- (void) drawRect: (CGRect) aRect
{
    UIImage *logo = [UIImageimageNamed:@"logo1.png"];
    CGRect bounds = CGRectMake(0.0f, 0.0f,rect.origin.x + aRect.size.width, rect.origin.y + aRect.size.height);
    // Create a new path
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGMutablePathRef path = CGPathCreateMutable();
   
    // Add circle to path
    CGPathAddEllipseInRect(path, NULL, bounds);//这句话就是剪辑作用
    CGContextAddPath(context, path);

    // Clip to the circle and draw the logo
    CGContextClip(context);
    [logo drawInRect:bounds];
    CFRelease(path);
}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics