iOS中的屏幕适配

iOS中的屏幕适配

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/109050.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号