您可以創建實用方法:
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
,並實現它:
UIImage *myIcon = [self imageWithImage:myImage scaledToSize:CGSizeMake(20, 20)]
希望這可以幫助。
爲什麼不嘗試更新imageView的框架大小? – ozgur
試圖更新我的框架的大小,但它不工作 –