iOS代码适配(2)
2015-06-09 15:08
417 查看
1. 首先我们看一下 iphone 5(s) ,iphone 6和6 plus 的屏幕比例
所以, 我们可以用比例来适配三者的屏幕.
2.在Appdelegate.h
@property float autoSizeScaleX;
@property float autoSizeScaleY;
如图所示:
3.在appDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
if(ScreenHeight > 480){
myDelegate.autoSizeScaleX = ScreenWidth/320;
myDelegate.autoSizeScaleY = ScreenHeight/568;
}else{
myDelegate.autoSizeScaleX = 1.0;
myDelegate.autoSizeScaleY = 1.0;
}
}
如图所示:
因为iPhone4s屏幕的高度是480,因此当屏幕尺寸大于iPhone4时,autoSizeScaleX和autoSizeScaleY即为当前屏幕和iPhone5尺寸的宽高比
5.在.pch中或者 全局的那种头文件里面写
CG_INLINE CGRect CGRectMakeScreen(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
CGRect rect;
rect.origin.x = x * myDelegate.autoSizeScaleX; rect.origin.y = y * myDelegate.autoSizeScaleY;
rect.size.width = width * myDelegate.autoSizeScaleX; rect.size.height = height * myDelegate.autoSizeScaleY;
return rect;
}
或者写到全局的头文件里面,我的是header.h
6.使用
用CGRectMakeScreen 代替原本的CGRectmake 就好了
所以, 我们可以用比例来适配三者的屏幕.
2.在Appdelegate.h
@property float autoSizeScaleX;
@property float autoSizeScaleY;
如图所示:
3.在appDelegate.m中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
if(ScreenHeight > 480){
myDelegate.autoSizeScaleX = ScreenWidth/320;
myDelegate.autoSizeScaleY = ScreenHeight/568;
}else{
myDelegate.autoSizeScaleX = 1.0;
myDelegate.autoSizeScaleY = 1.0;
}
}
如图所示:
因为iPhone4s屏幕的高度是480,因此当屏幕尺寸大于iPhone4时,autoSizeScaleX和autoSizeScaleY即为当前屏幕和iPhone5尺寸的宽高比
5.在.pch中或者 全局的那种头文件里面写
CG_INLINE CGRect CGRectMakeScreen(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
AppDelegate *myDelegate = [[UIApplication sharedApplication] delegate];
CGRect rect;
rect.origin.x = x * myDelegate.autoSizeScaleX; rect.origin.y = y * myDelegate.autoSizeScaleY;
rect.size.width = width * myDelegate.autoSizeScaleX; rect.size.height = height * myDelegate.autoSizeScaleY;
return rect;
}
或者写到全局的头文件里面,我的是header.h
6.使用
用CGRectMakeScreen 代替原本的CGRectmake 就好了
相关文章推荐
- iOS开发多线程篇—GCD介绍
- IOS 沙盒(sandbox)机制和文件操作
- [iOS diary]CABasicAnimation KeyPath大全与使用事例
- iOS Ad-Hoc 内测笔记
- IOS 实现键盘弹出视图上移功能
- 如何在未越狱iOS设备上安装IPA
- 制作iOS Ad-Hoc测试应用
- 启动图和屏幕适配的关系
- IOS开发基础知识--碎片14
- iOS项目的持续集成与管理
- iOS开发常用快捷键
- ios Cocoa error 4097
- iOS QQ第三方登实现
- win7 bios引导启动Ubuntu
- iOS地理反地理编码--CoreLocation
- ios数据持久化(转)
- iOS8推送消息的回复处理速度
- iOS 2d自定义绘图浅析
- iOS XCode启用/关闭Clang Warnings
- IOS去掉导航条一条线 navigationBar去掉一条线,改变状态栏默认颜色