https://github.com/LZY-WLY/CircleImage
- (UIImage *)circleImage {
? ? //開啟圖片上下文
? ? UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
? ? //獲得上下文
? ? CGContextRef ctx = UIGraphicsGetCurrentContext();
? ? //添加一個(gè)圓
? ? CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
? ? CGContextAddEllipseInRect(ctx, rect);
? ? //剪接
? ? CGContextClip(ctx);
? ? //將圖片畫上去
? ? [selfdrawInRect:rect];
? ? //得到圖片
? ? UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
? ? //結(jié)束圖片上下文
?? ?UIGraphicsEndImageContext();
? ? returnimage;
}