- (UIImage*)imageWithCornerRadius:(CGFloat)radius {
// 开始图形上下文
UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0);
// 获得图形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 设置一个范围
CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
// 根据radius的值画出路线
CGContextAddPath(ctx, [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
// 裁剪
CGContextClip(ctx);
// 将原照片画到图形上下文
[self drawInRect:rect];
// 从上下文上获取剪裁后的照片
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
// 关闭上下文
UIGraphicsEndImageContext();
return newImage;
}