Ios 四舍五入UIImage方法不适用于';不行?
使用此方法,无论我为Ios 四舍五入UIImage方法不适用于';不行?,ios,uiimageview,uiimage,drawing,Ios,Uiimageview,Uiimage,Drawing,使用此方法,无论我为CGFloat参数输入什么,0,1,甚至100。我的UIImage始终有一个圆角,即使我将参数设置为0。UIImage所在的MyUIImageView被设置为缩放以填充,如果这有任何区别 不管怎样,这个方法有什么问题吗 //Rounded UIImage - (UIImage*)roundCorneredImage: (UIImage*)orig radius:(CGFloat) r { UIGraphicsBeginImageContextWithOptio
CGFloat
参数输入什么,0
,1
,甚至100
。我的UIImage
始终有一个圆角,即使我将参数设置为0
。UIImage
所在的MyUIImageView
被设置为缩放以填充,如果这有任何区别
不管怎样,这个方法有什么问题吗
//Rounded UIImage
- (UIImage*)roundCorneredImage: (UIImage*)orig radius:(CGFloat) r {
UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0);
[[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size}
cornerRadius:r] addClip];
[orig drawInRect:(CGRect){CGPointZero, orig.size}];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
你的方法很好用。我在我的环境中试过。所以,错误应该位于代码段之外的某个地方。您确定要将返回的图像用于UIImageView吗?是,因为否则我的UIImageView中将没有图像。但这很奇怪,因为即使我使用0,我的图像仍然是圆形的!我是在黑暗中拍摄的,但是否有可能您意外地将cornerRadius应用于UIImageView的图层?与您的代码片段完全相同的代码片段在我的环境中完全可以正常工作。是的,这就是问题所在,谢谢!现在可以了!