iOS中的屏幕适配
2016-04-28 00:00
423 查看
iOS中的屏幕适配
在AppDelegate.h文件中
在AppDelegate.m文件中
设置在4S、5、5S、6、6P、6S、6SP等不同尺寸屏幕上的适配
在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];
相关文章推荐
- iOS中收回键盘
- iOS中判断程序是不是第一次运行(新手引导界面用)
- iOS中各种手机型号的分辨率及软件图标的制作
- iOS中单例NSUserDefaults的使用 (转)
- iOS获取设备型号、设备类型等信息
- ios 播放声音文件
- iOS CocoaPods安装和使用图解
- ios极光推送使用总结
- ios 摇一摇
- iOS开发之传感器
- iOS Block
- ios 十六进制与十进制转换
- iOS获取当前时间及前一天或后一天时间
- iOS 中KVC、KVO、NSNotification、delegate 总结及区别
- iOS 页面传值总结
- iOS hidesBackButton正确姿势 ios键盘联想屏蔽
- Ios userDefaultes本地存储
- 字典中添加不同类型的值(ios)
- iOS 蓝牙开发流程
- iOS开发多线程篇—创建线程