【发布时间】:2015-01-07 11:39:20
【问题描述】:
我们想在代码中设置一个适合 iPhone5 和 iPhone6 的图像。
我们有一个图像,它的大小已准备好用于 iPhone6 ,我们希望它被缩放并放置在 iPhone5 上的相同位置。
所以,下一个代码在 iPhone6 上运行良好,但在 iPhone5 上,图像没有缩放,我猜是因为我采用 实际图像 的大小,而不是比例到屏幕尺寸:
(我在应用程序上也有启动图像)
UIImage *imgt=[UIImage imageNamed:@"title.png"];
UIImageView *title=[[UIImageView alloc] initWithFrame:CGRectMake((width-imgt.size.width)/2.0,imgt.size.height/2.0, imgt.size.width, imgt.size.height)];
title.image=imgt;
[self.view addSubview:title];
问题是,我怎样才能在 iPhone5s 上获得 缩放的图像尺寸 ?他所做的是取实际尺寸(iPhone6 的大尺寸),但因为我知道图像尺寸是按比例缩放的,我希望得到缩放后的尺寸 imgt.size.width
【问题讨论】:
-
您查看过
UIImageView的contentMode吗?如果你只是在做一个全屏UIImage,它可能是一个简单的例子,将UIImageView.contentMode设置为UIViewContentModeScaleAspectFit或UIViewContentModeScaleAspectFill。
标签: ios objective-c