为iPhone 5加载不同的xib
发布时间:2020-12-14 20:03:47 所属栏目:百科 来源:网络整理
导读:我的应用程序为iPhone 5提供了额外的功能,我为它创建了一个单独的带有.xib的类.我想检测屏幕高度(除非可以获取设备ID /型号)并相应地加载不同的视图控制器.我试过这个: - (IBAction)select:(id)sender {CGRect screenRect = [[UIScreen mainScreen] bounds]
我的应用程序为iPhone 5提供了额外的功能,我为它创建了一个单独的带有.xib的类.我想检测屏幕高度(除非可以获取设备ID /型号)并相应地加载不同的视图控制器.我试过这个:
- (IBAction)select:(id)sender { CGRect screenRect = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenRect.size.width; CGFloat screenHeight = screenRect.size.height; if (screenHeight == 960) { Selection *selectView =[[Selection alloc] initWithNibName:nil bundle:nil]; selectView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:selectView animated:YES]; } else { Selection_5 *selectView =[[Selection_5 alloc] initWithNibName:nil bundle:nil]; selectView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentModalViewController:selectView animated:YES]; } } Selection和Selection_5是两个不同的类,每个类都有一个用户界面的不同xib. 解决方法
试试
http://github.com/erica/uidevice-extension/
[[UIDevice currentDevice] platformType] // ex: UIDevice4GiPhone [[UIDevice currentDevice] platformString] // ex: @"iPhone 4G" 或者你可以只看屏幕高度: float screenHeight = [UIScreen mainScreen].bounds.size.height; iPhone 5的高度为568 如果你用.xib加载,你可能会shell设置nib: [[Selection alloc] initWithNibName:@"here_is_nibname" bundle:nil]; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |