如何使xib兼容iphone 5和iphone 4设备 [英] How to make xib compatible with both iphone 5 and iphone 4 devices

查看:117
本文介绍了如何使xib兼容iphone 5和iphone 4设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试布局我的xib,以便布局适合iphone 5(4英寸视网膜)和3.5设备。

I am trying to layout my xib so that layout fits in both iphone 5 (4 inches retina) and 3.5 devices.

因为我必须支持IOS-5,所以我不能使用autolayout。我必须使用spring和Struts。

Because I have to support IOS-5 I cannot use autolayout. I have to use springs and Struts.

我在interface-builder中尝试了所有内容。但要么我的观点超出了iphone-3.5英寸的底部,要么完全没有填充iphone-4英寸视网膜。

I tried everything in interface-builder. But either my view is going beyond the bottom of iphone-3.5-inch or not filling completely the iphone-4-inch-retina.

有人可以提示如何让xib与这两种设备兼容吗?

Can someone give a hint how to actually make an xib compatible to both the devices?

为了更清晰我正在添加屏幕截图:

For more clarity I am adding screenshots:

当我在属性检查器中设置大小为3.5时:

When I set size 3.5 in attribute inspector:

时,它会在iphone-5中查找。按钮下面有一个空格:

it looks in iphone-5. There is a space below the buttons:

如果我在界面构建器中设置了4英寸的大小。您可以看到底部按钮在iphone-4中不可见。

If I set size 4 inch in interface builder. You can see that bottom buttons are not visible in iphone-4.

所以你会问我正在使用的设置是什么。以下是:

So you will ask what are the settings I am using. Here are they:



推荐答案


  1. 为UIviewController添加新类别并在.h文件中添加此代码

  1. You add new category for UIviewController and add this code in .h file

 - (id)initWithNibNameforIphone4:(NSString *)nibNameOrNil4 NibNameforIphone5:(NSString *)nibNameOrNil5 NibNameforIpad:(NSString *)nibNameOrNilpad bundle:(NSBundle *)nibBundleOrNil;


  • 在.m文件中添加此代码

  • Add this code in your .m file

     - (id)initWithNibNameforIphone4:(NSString *)nibNameOrNil4 NibNameforIphone5:(NSString *)nibNameOrNil5 NibNameforIpad:(NSString *)nibNameOrNilpad bundle:(NSBundle *)nibBundleOrNil
     {
       if (self = [super init])
     {
      self = [self initWithNibName:[self CheckDeviceIphone4:nibNameOrNil4 Iphone5:nibNameOrNil5 Ipad:nibNameOrNilpad] bundle:nibBundleOrNil];
      }
      return self;
    
    }
    
      -(NSString *)CheckDeviceIphone4:(NSString *)iphone4 Iphone5:(NSString *)iphone5 Ipad:(NSString *)ipad {
    
        return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) ? ipad :([[UIScreen mainScreen] bounds].size.height == 568) ?  iphone5 :iphone4;
      }
    


  • 打开YouProject-Prefix.pch文件并在此处导入您的类别

  • Open YouProject-Prefix.pch file and import your category here

    现在你只需在这样的项目中使用它

    now you just use this in all over project like this

     self.firstView=[[firstView alloc]initWithNibNameforIphone4:@"firstView4" NibNameforIphone5:@"firstView" NibNameforIpad:@"firstViewIpad" bundle:[NSBundle mainBundle]];
    

    谢谢和任何问题然后评论并且不要忘记upvote: - )

    thanks and any question then comment and dont forget to upvote :-)

    \

    这篇关于如何使xib兼容iphone 5和iphone 4设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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