iOS開發UI篇—Quartz2D使用(圖片剪切)spa
1 - (void)drawRect:(CGRect)rect 2 { 3 UIImage *image2=[UIImage imageNamed:@"me"]; 4 [image2 drawAtPoint:CGPointMake(100, 100)]; 5 }
顯示:code
1 - (void)drawRect:(CGRect)rect 2 { 3 //畫圓,以便之後指定能夠顯示圖片的範圍 4 //獲取圖形上下文 5 CGContextRef ctx=UIGraphicsGetCurrentContext(); 6 CGContextAddEllipseInRect(ctx, CGRectMake(100, 100, 50, 50)); 7 8 //指定上下文中能夠顯示內容的範圍就是圓的範圍 9 CGContextClip(ctx); 10 UIImage *image2=[UIImage imageNamed:@"me"]; 11 [image2 drawAtPoint:CGPointMake(100, 100)]; 12 }
1 - (void)drawRect:(CGRect)rect 2 { 3 4 //畫三角形,以便之後指定能夠顯示圖片的範圍 5 //獲取圖形上下文 6 CGContextRef ctx=UIGraphicsGetCurrentContext(); 7 // CGContextAddEllipseInRect(ctx, CGRectMake(100, 100, 50, 50)); 8 CGContextMoveToPoint(ctx, 100, 100); 9 CGContextAddLineToPoint(ctx, 60, 150); 10 CGContextAddLineToPoint(ctx, 140, 150); 11 CGContextClosePath(ctx); 12 13 14 //注意:指定範圍(也就是指定剪切的方法必定要在繪製範圍以前進行調用) 15 //指定上下文中能夠顯示內容的範圍就是圓的範圍 16 CGContextClip(ctx); 17 UIImage *image2=[UIImage imageNamed:@"me"]; 18 [image2 drawAtPoint:CGPointMake(100, 100)]; 19 }
顯示:blog