如何在imageview ios7中获取圆形图像

时间:2014-03-17 11:10:10

标签: ios ios7 uiimageview uiimage

如何从UIImage获取圆形图像并将其显示在图像视图上。图像应该与IOS7中显示的图像一样调用历史记录

1 个答案:

答案 0 :(得分:2)

- (UIImage *)getRoundedRectImageFromImage :(UIImage *)image onReferenceView :  
(UIImageView*)imageView withCornerRadius :(float)cornerRadius
{
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds
                            cornerRadius:cornerRadius] addClip];
[image drawInRect:imageView.bounds];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return finalImage;
}                                                                                                     And call the method like this

imageView.image = [self getRoundedRectImageFromImage:image
                                         onReferenceView:
imageView withCornerRadius:imageView.frame.size.width/2];
imageView.clipsToBounds=YES;
imageView.layer.masksToBounds = YES;