gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:12:56 25 4
gpt4 key购买 nike

如何从 UIImage 获取圆形图像并将其显示在 ImageView 上。该图像应该类似于 IOS7 调用历史中显示的图像

最佳答案

- (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;

关于ios - 如何在 imageview ios7 中获取圆形图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22452771/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com