【发布时间】:2012-10-19 10:23:50
【问题描述】:
在我的FirstViewController 中,如果设备是 iPhone4 或 iPhone5,我已经编写了用于切换背景的代码:
文件名:
bg-for5-568@2x.png
bg-for4@2x.png
bg-for4.png
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *backgroundImage = [[UIImage alloc] init];
if([[UIScreen mainScreen]bounds].size.height == 568)
{
backgroundImage = [UIImage imageNamed:@"bg-for5-568h"];
}
else
{
backgroundImage = [UIImage imageNamed:@"bg-for4"];
}
self.view.backgroundColor = [[[UIColor alloc] initWithPatternImage:backgroundImage] autorelease];
[backgroundImage release];
}
当我在我的模拟器上启动应用程序时,iphone5 的背景显示为两倍大小,超出了视图。
/* 已解决,谢谢*/
【问题讨论】:
-
它将加倍大小,因为它是双倍大小,iOS 将对其进行拉伸,以便图像的 1 个像素将显示在图形窗格的 1.0“像素”中,该窗格在视网膜设备上拉伸超过 2 个硬件像素.有几种方法可以处理这个问题。最简单的方法是将该行代码中的“bg-for5-568h@2x”更改为“bg-for5-568h”,但不要更改 png 文件的名称。
-
非常感谢!现在完美的作品。
标签: iphone objective-c ios cocoa-touch