gpt4 book ai didi

iphone - 如何使 xib 同时兼容 iphone 5 和 iphone 4 设备

转载 作者:行者123 更新时间:2023-12-03 18:12:01 24 4
gpt4 key购买 nike

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

因为我必须支持 IOS-5,所以我无法使用自动布局。我必须使用 Spring 和 Struts。

我尝试了界面生成器中的所有内容。但我的观点要么超出了 iphone-3.5 英寸的底部,要么没有完全填满 iphone-4 英寸的视网膜。

有人可以提示如何真正使 xib 兼容这两种设备吗?

为了更清楚起见,我添加了屏幕截图:

当我在属性检查器中设置大小 3.5 时: When I set size in attribute inspector to 3.5

它看起来像 iphone-5。按钮下方有一个空格: And this is how it looks in simulator for 3.5 inch device

如果我在界面生成器中设置尺寸 4 英寸。您可以看到底部按钮在 iphone-4 中不可见。 If I set size 3.5 inch in interface builder

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

enter image description here enter image description here enter image description here

最佳答案

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

     - (id)initWithNibNameforIphone4:(NSString *)nibNameOrNil4 NibNameforIphone5:(NSString *)nibNameOrNil5 NibNameforIpad:(NSString *)nibNameOrNilpad bundle:(NSBundle *)nibBundleOrNil;
  2. 将此代码添加到您的 .m 文件中

     - (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;
    }
  3. 打开 YouProject-Prefix.pch 文件并在此处导入您的类别

  4. 现在你只需在像这样的所有项目中使用它

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

    谢谢,有任何问题请评论,不要忘记投票:-)

\

关于iphone - 如何使 xib 同时兼容 iphone 5 和 iphone 4 设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13275144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com