一下方法寫在自定義的ImageView中.
// 創(chuàng)建一個(gè)圖片上下文
UIGraphicsBeginImageContext(self.size);
// 指定半徑
CGFloat radius = 50;
UIBezierPath *path =[UIBezierPath bezierPathWithRect:self.bounds];
UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(self.centerX - radius, self.centerY - radius, 2.0*radius, 2.0*radius) cornerRadius:radius];
[path appendPath:circlePath];
[path setUsesEvenOddFillRule:YES];
[path addClip]; // 裁剪
// 繪制圖片到圖片上下文中
[self.image drawInRect:self.bounds];
self.image = UIGraphicsGetImageFromCurrentImageContext();
//關(guān)閉圖片上下文
UIGraphicsEndImageContext();