Xcode - 如何检测iPhone的屏幕尺寸 [英] Xcode - How do I Detecting screen size of iPhone

查看:117
本文介绍了Xcode - 如何检测iPhone的屏幕尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个xib,一个用于iPhone 4,一个用于iPhone 5; 3.5英寸和4英寸。我只是想放一些代码告诉应用程序加载哪个。我有这个代码应该做的工作:

I have two xibs, one for the iPhone 4 and one for the iPhone 5; 3.5 inch and 4 inch. I simply want to put some code that tells the app which to load. I have this code which is supposed to do the job:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone))
{
    CGSize result = [[UIScreen mainScreen] bounds].size;
    if(result.height == 480)
    {
    //Load 3.5 inch xib
    }
    if(result.height == 568)
    {
        //Load 4 inch xib
    }

我把它放入ViewController.M(是我把它放在哪里?)并且构建失败说有一个解析问题预期标识符为(
任何人都可以帮我解决这个简单的问题吗?谢谢!

I put it in the ViewController.M(is that where I put it?) and the build fails saying there is a parse issue expected identifier of "(" Can anyone help me with this simple fix? Thanks!

推荐答案

在prefix.pch文件中添加以下行...这是检查屏幕大小的最简单方法,无需额外添加代码行。 。

add below line in your prefix.pch file...this is the simplest way to check screen size, no need to make extra lines of code...

#define   IsIphone5     ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )

现在,无论你想检查屏幕尺寸,只需调整如下条件,你可以做任何你想做的事....

now whereever you want to check screen size , just make condition like below, and you can do whatever you want....

 if(IsIphone5)
{
    //your stuff
}
else
{  
  //your stuff
}

快乐编码!!!!

这篇关于Xcode - 如何检测iPhone的屏幕尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆