寫(xiě)在前面:實(shí)際工作中播歼,有時(shí)候需要按照需求將圖片裁剪成圓形,或者你需要的形狀栅盲。這里以圓形為例舔庶。
核心:void CGContextClip(CGContextRefc)
將當(dāng)前上下文繪制的路徑裁剪出來(lái),超出這個(gè)范圍的內(nèi)容不顯示箱沦。
代碼如下:
CGContextRef ctx = UIGraphicsGetCurrentContext();
畫(huà)出路徑
CGRectrect =CGRectMake(100,100,50,50);
CGContextAddEllipseInRect(ctx,rect);
CGContextClip(ctx);
CGContextFillPath(ctx);
UIImage*image = [UIImageimageNamed:@"xx"]; ?
[image drawAtPoint:CGPointMake(100,100)];