iPhoneでコードを開発するのは初めてです。コードを検索して、UIImageのサイズを指定したサイズに変更しますが、比率は維持します。指定されたサイズは、画像が境界を越えることができないフレームのようなものです。その境界内では、画像はフレームに合わせて拡大縮小され、比率を維持する必要があります。現在使用しているコードはサイズ変更はできますが、維持することはできません。比率をここに貼り付けて、それを可能にするためにいくつかの些細な変更を行うことができるかどうかを確認します。
- (UIImage *)resizeImage:(UIImage*)image newSize:(CGSize)newSize {
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, newSize.width, newSize.height));
CGImageRef imageRef = image.CGImage;
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the quality level to use when rescaling
CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, newSize.height);
CGContextConcatCTM(context, flipVertical);
// Draw into the context; this scales the image
CGContextDrawImage(context, newRect, imageRef);
// Get the resized image from the context and a UIImage
CGImageRef newImageRef = CGBitmapContextCreateImage(context);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGImageRelease(newImageRef);
UIGraphicsEndImageContext();
return newImage;
}