IOS开发中常用一下方法

时间:2021-06-12 23:05:15

1.获得屏幕的宽高

  [UIScreen mainScreen].bounds.size.width

[UIScreen mainScreen].bounds.size.height

2.Iphone版本判别:

  iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,1136), [[UIScreen mainScreen] currentMode].size) : NO)

  iPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640,960), [[UIScreen mainScreen] currentMode].size) : NO)

  Phone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750,1334), [[UIScreen mainScreen] currentMode].size) : NO)

  iPhone6plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242,2208), [[UIScreen mainScreen] currentMode].size) : NO)

3.Iphone、Ipad、Ipod判别:

  [UIDevice currentDevice].model

4.获得Documents路径:

  NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *path = [array lastObject];

5.获得mp路径:

  NSString *tmp = NSTemporaryDirectory();

6.获取当前Iphone的语言环境:

  NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];

NSArray* languages = [defs objectForKey:@"AppleLanguages"];

NSString* preferredLang = [languages objectAtIndex:0];