以下可讲视图裁剪成一个圆形或椭圆:
- (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); }