iOS中的屏幕适配
在AppDelegate.h文件中
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> //屏幕的尺寸 @property float autoSizeScaleX; @property float autoSizeScaleY; @property (strong, nonatomic) UIWindow *window; @end
在AppDelegate.m文件中
#import "AppDelegate.h" #import "HomeViewController.h" #import "FMDatabase.h" #define ScreenWidth [UIScreen mainScreen].bounds.size.width #define ScreenHeight [UIScreen mainScreen].bounds.size.height @interface AppDelegate () { //创建一个导航控制器 UINavigationController *nav; } @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //按比例适配屏幕 AppDelegate *myDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; if(ScreenWidth == 667){ myDelegate.autoSizeScaleX = 1.0; myDelegate.autoSizeScaleY = 1.0; } else{ myDelegate.autoSizeScaleX = ScreenWidth/375; myDelegate.autoSizeScaleY = ScreenHeight/667; } //让当前的window成为主窗口 [self.window makeKeyAndVisible]; //首页(可以写登录页面) HomeViewController *homeVC = [[HomeViewController alloc]init]; //创建一个导航控制器 nav= [[UINavigationController alloc]initWithRootViewController:homeVC]; self.window.rootViewController = nav;
设置在4S、5、5S、6、6P、6S、6SP等不同尺寸屏幕上的适配
//设置界面上的画面 UIImageView * showView= [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen]bounds ].size.width, [[UIScreen mainScreen]bounds ].size.height)]; showView.image = [UIImage imageNamed:@"新建View"]; [self.view addSubview:showView];
转载于:https://my.oschina.net/LBBB/blog/667592
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/109050.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...