问题描述
- 怎么判断IOS设备的版本
-
有两个storyboard分别制定给iPhone5和iPhone4的尺寸。如何让代码检测ios版本?- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 1 UIStoryboard * mainStoryboard = nil ; if ( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO ( @ "6.0" ) ) { mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhones6.0" bundle : nil ] ; } else { mainStoryboard = [ UIStoryboard storyboardWithName : @ "iPhones3-5" bundle : nil ] ; } // 2 self.window = [ [ UIWindow alloc ] initWithFrame : [ [ UIScreen mainScreen ] bounds ] ] ; self.window.rootViewController = [ mainStoryboard instantiateInitialViewController ] ; [ self.window makeKeyAndVisible ] ; return YES; }
解决方案
判断是否为iphone5的宏
#define IPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : 0)
解决方案二:
这个不对吧,版本代表不了手机型号,为何不去获取物理屏幕大小好了呢?
解决方案三:
其实一个storyboard就可以适配iphone5,iphone4的尺寸。在storyboard中可以设置UI元素的约束来定位位置,这里需要用到NSLayoutConstrant 技术
时间: 2024-10-21 20:51:31