iOS - 支持iPad和iPad iPhone没有使用笔尖 [英] iOS - Support iPad & iPhone without using nib
问题描述
我正在尝试编写应用而不使用 nib ,我会以编程方式执行此操作。
I'm trying to write an app without using nib, everything I'll do it programmatically.
现在的问题是,我如何支持 iPad 和 iPhone ?显然,我不能用
Now the problem is, how am I going to support both iPad and iPhone? Obviously, I can't do it with
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// load iPad nib
} else {
// load iPhone nib
}
如果我创建2 ViewControllers ,那么 IBAction
将是多余的。
If I create 2 ViewControllers, then the IBAction
will be redundant.
有什么建议吗?
推荐答案
您应该只是在 applicationDidFinishLaunching <中找出设备类型/ code>然后为每个设备加载单独的控制器。但是如果你想为所有设备只有一个实现,那么做这样的检查:
You should probably just figure out the device type in applicationDidFinishLaunching
and then load separate controllers for each device. But if you want to just have a single implementation for all devices, do checks like this:
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
//do some iPad stuff
}
else
{
CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
if([UIScreen mainScreen].scale == 2.f && screenH == 568.0f)
{
//do iPhone 5 stuff
}
else
{
//do iPhone 4S and iPhone 4 stuff
//the dimensions are the same however, if you want to do iPhone 4S specific stuff
// you'll need to do additional checks against video resolution or other differences etc
}
}
这篇关于iOS - 支持iPad和iPad iPhone没有使用笔尖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!