本文主要是介绍IOS开发——3.5/4英寸屏幕适配,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
IOS开发——3.5/4英寸屏幕适配
方法一:
哪里需要就在哪里写:
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.view.bounds = app.window.screen.bounds;
方法二:
预编译文件里面写:
#define DEVICE_3_5_INCH ([[UIScreen mainScreen] bounds].size.height == 480)
#define DEVICE_4_0_INCH ([[UIScreen mainScreen] bounds].size.height == 568)
VC中初始化时再判断:
if(DEVICE_3_5_INCH){[self.view setFrame:CGRectMake(0,20, 320, 460)];}if(DEVICE_4_0_INCH){[self.view setFrame:CGRectMake(0,20, 320, 548)];}
方法三:@interface HomeViewController ()
{
int H;int hh;
}
-(void)fetVer
{int ver = [[self fetchSystemVersion] intValue];NSString* iphone = [self fetchDevice];if([iphone isEqual:@"iphone5"]){H = 568;}else{H = 480;}if(ver < 7){hh = 0;}else{hh = 20;}
}
- (NSString *)fetchSystemVersion
{
return [[UIDevice currentDevice] systemVersion];
}
- (NSString *)fetchDevice{
CGRect rect = [UIScreen mainScreen].bounds;
float scale = [UIScreen mainScreen].scale;
float height = rect.size.height * scale;
NSString* strDevice = @"iphone4";
if (height == 480) {
strDevice = @"iphone3gs";
} else if(height == 1136){
strDevice = @"iphone5";
}
return strDevice;
}
这篇关于IOS开发——3.5/4英寸屏幕适配的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!