目前,我正在做这种类型的 View ,最好的方法是什么,这样我就可以管理不同比例的图像
我们有这个尺寸,
Device Points Pixels Scale Physical Pixels Physical PPI Size
iPhone 6 Plus 736x414 2208x1242 3x 1920x1080 401 5.5"
iPhone 6 667x375 1334x750 2x 1334x750 326 4.7"
iPhone 5 568x320 1136x640 2x 1136x640 326 4.0"
iPhone 4 480x320 960x640 2x 960x640 326 3.5"
iPhone 3GS 480x320 480x320 1x 480x320 163 3.5"
我的问题 是来自服务器的图像我想在所有类型的 Apple 设备中处理此图像,我在单元格中使用纵横比适合,当我使用 640 * 106 尺寸时我-phone 6plus 此图像未正确显示大小
这是我的代码
CGRect frameIphone = (flag) ? CGRectMake(0, 0, self.view.frame.size.width, 106):CGRectMake(0, 0, self.view.frame.size.width, 106);
UIImageView *img = [[UIImageView alloc] initWithFrame:(iPad) ? CGRectMake(10,8,55,55) : frameIphone];
img.tag = indexPath.section;
img.contentMode = UIViewContentModeScaleAspectFit;
img.layer.masksToBounds = YES;
[img sd_setImageWithURL:[NSURL URLWithString:[objClass getImageForBackground]] placeholderImage:nil]; // URL Images
最佳答案
其实并不难,因为你所做的是固定 View 的宽度/高度,你需要做的是根据屏幕比例计算并给它正确的高度,因为宽度是根据屏幕宽度固定的,比如屏幕是iphone 6plus,点数是736x414
,图片是640x106
,你计算一下736*109/640
(screen width * image height/image width, change with variable) = 125, 那是你应该使用的imageView高度,而不是直接106
你可以先把图片设置到image view,再配置它的frame也可以,这样你就可以得到图片的高/宽
关于ios - 如何处理不同设备上的图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38913279/