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