我正在尝试布局我的 xib,以便该布局适合 iphone 5(4 英寸视网膜)和 3.5 设备。
因为我必须支持 IOS-5,所以我无法使用自动布局。我必须使用弹簧和支柱。
我尝试了界面生成器中的所有内容。但我的观点要么超出了 iphone-3.5 英寸的底部,要么没有完全填满 iphone-4 英寸的视网膜。
有人可以提示如何真正使 xib 兼容这两种设备吗?
为了更清楚起见,我添加了屏幕截图:
When I set size 3.5 in attribute inspector:
it looks in iphone-5. There is a space below the buttons:
If I set size 4 inch in interface builder. You can see that bottom buttons are not visible in iphone-4.
所以你会问我正在使用什么设置。他们是这样的:
-
您为 UIviewController 添加新类别并将此代码添加到 .h 文件中
- (id)initWithNibNameforIphone4:(NSString *)nibNameOrNil4 NibNameforIphone5:(NSString *)nibNameOrNil5 NibNameforIpad:(NSString *)nibNameOrNilpad bundle:(NSBundle *)nibBundleOrNil;
-
将此代码添加到您的 .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;
}
打开 YouProject-Prefix.pch 文件并在此处导入您的类别
-
现在你只需在像这样的整个项目中使用它
self.firstView=[[firstView alloc]initWithNibNameforIphone4:@"firstView4" NibNameforIphone5:@"firstView" NibNameforIpad:@"firstViewIpad" bundle:[NSBundle mainBundle]];
谢谢,有任何问题请评论,不要忘记投票:-)
\
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)