我需要按宽度按比例调整UI Image,可能有人有工作代码吗? 例如: Input: Width: 900 Height: 675. Resize to width: 400 width Result: Width: 400 Height: 300 请帮忙.. 检查 this blog post.特别是这两个文件: UII
例如:
Input: Width: 900 Height: 675. Resize to width: 400 width
Result: Width: 400 Height: 300
请帮忙..
检查 this blog post.特别是这两个文件:> UIImage+Resize.h
> UIImage+Resize.m
也许这对你有用:
UIImage *image = [UIImage imageNamed:@"SomeImage-900x675"]; // SomeImage-900x675.png CGFloat targetWidth = 400.0f; CGFloat scaleFactor = targetWidth / image.size.width; CGFloat targetHeight = image.size.height * scaleFactor; CGSize targetSize = CGSizeMake(targetWidth, targetHeight); UIImage *scaledImage = [image resizedImage:targetSize interpolationQuality:kCGInterpolationHigh];