0
尝试获得基于另一个的UIImageView一个圆形的UIImage:如何调整UIImageView边界以剪裁圆角UIImage?
1)的UIImageView被称为:
@interface CompetitorAnalysisViewController()
@property (weak, nonatomic) IBOutlet UIImageView *submitImageButton;
@end
2)回合的UIImage:
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
// Round the image
UIImage *roundedChosenImage = [self getRoundedRectImageFromImage:chosenImage onReferenceView:_submitImageButton withCornerRadius: _submitImageButton.frame.size.width/2];
3)如何圆UIImage:
- (UIImage *)getRoundedRectImageFromImage :(UIImage *)image onReferenceView :(UIImageView*)imageView withCornerRadius :(float)cornerRadius
{
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 0);
[[UIBezierPath bezierPathWithRoundedRect:imageView.bounds
cornerRadius:cornerRadius] addClip];
[image drawInRect:imageView.bounds];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return finalImage;
}
问题:
我想剪裁UIImage(不是UIImageView)是一个四舍五入的。然而,我现在得到的圆形UIImage比我想要的要大。
我应该以某种方式调整“imageView.bounds”吗?如果我可以按比例调整它,这将是非常好的。
或者其他更好的方法来实现呢?
我认为你在正确的轨道 - 只是改变'imageView.bounds'的大小,然后当你'drawInRect'时,它会是你想要的大小。 – brandonscript
@brandonscript我是新来的Objective-C,并在网上搜索,但没有找到如何真正改变imageView.bounds的大小...任何建议? –
'imageView.bounds = CGRectMake(X,Y,L,W)'应该这样做 – brandonscript