您可以使用的功能之一称为 AutoLayout。它与 Xcode 一起提供,以便更轻松地为 4 英寸屏幕进行调整。你可以在这里找到一个很好的例子:http ://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2
但据我所知,AutoLayout 仅适用于 iOS 6,这使得它“还没有那么有用”。我一直在使用一个名为 的类UIDevice
,其来源可以在这里找到:https ://github.com/erica/uidevice-extension并检查平台类型是否为 iPhone 5。我在设置 GUI 的方法中设置了它当视图加载时。我的实现示例:
UIImage *backgroundImage;
if ([[UIDevice currentDevice] platformType] == UIDevice5iPhone)
{
//I have a 4 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 5
backgroundImage = [[UIImage alloc] initWithCGImage:[UIImage imageNamed:@"main_background-568h@2x"].CGImage scale:2.0 orientation:UIImageOrientationUp];
}
else
{
//I have a 3.5 inch screen present
myButton.frame = CGRectMake(x, y, w, h); //Set the frame as you would like it to look on the iPhone 3, 3gs, 4, 4s...
backgroundImage = [[UIImage imageNamed:@"main_background"] retain];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:backgroundImage];
[backgroundImage release];
希望它清除一点。