iOS开发——屏幕尺寸适配
2016-01-26 16:03
495 查看
对于屏幕尺寸适配,目前先指竖屏的方式适合方式1和2。
1.控件尺寸写死的方式,偶尔会用到屏幕的宽度和高度。
UILabel *holdLabel = [[UILabel alloc]initWithFrame:CGRectMake(12, 42, 100, 20
)];
[[UIButton alloc] initWithFrame:CGRectMake(self.width - 65, 0, 80, 80)];
其中 self.width = [UIScreen mainScreen].bounds.size.width;
2.是在第一种的基础上乘上屏幕的宽高比
self.beginDate = [[UILabel alloc]initWithFrame:CGRectMake(12* ScreenWidthRate, 145* ScreenHeightRate,width/2 -12* ScreenWidthRate, 15* ScreenHeightRate)];
其中,ScreenWidthRate和ScreenHeightRate 是在pch文件里定义好的,如下: (比例根据UI图)
#define ScreenHeightRate ([[UIScreen mainScreen] bounds].size.height / 667.0) //6 plus 736 6s/6 667 5s 568
#define ScreenWidthRate ([UIScreen mainScreen].bounds.size.width / 375.0)
static inline float screenHeightRate() {
CGFloat width = [UIScreen mainScreen].bounds.size.height;
return width / 667.0;
}
static inline float screenWidthRate() {
CGFloat width = [UIScreen mainScreen].bounds.size.width;
return width / 375.0;
}
#endif
3.第三种的屏幕适配是采用目前流行的Masonry 自动布局
这个推荐使用,并单独一篇博客介绍。
适合复杂cell里的控件布局和横竖屏的适配。
1.控件尺寸写死的方式,偶尔会用到屏幕的宽度和高度。
UILabel *holdLabel = [[UILabel alloc]initWithFrame:CGRectMake(12, 42, 100, 20
)];
[[UIButton alloc] initWithFrame:CGRectMake(self.width - 65, 0, 80, 80)];
其中 self.width = [UIScreen mainScreen].bounds.size.width;
2.是在第一种的基础上乘上屏幕的宽高比
self.beginDate = [[UILabel alloc]initWithFrame:CGRectMake(12* ScreenWidthRate, 145* ScreenHeightRate,width/2 -12* ScreenWidthRate, 15* ScreenHeightRate)];
其中,ScreenWidthRate和ScreenHeightRate 是在pch文件里定义好的,如下: (比例根据UI图)
#define ScreenHeightRate ([[UIScreen mainScreen] bounds].size.height / 667.0) //6 plus 736 6s/6 667 5s 568
#define ScreenWidthRate ([UIScreen mainScreen].bounds.size.width / 375.0)
static inline float screenHeightRate() {
CGFloat width = [UIScreen mainScreen].bounds.size.height;
return width / 667.0;
}
static inline float screenWidthRate() {
CGFloat width = [UIScreen mainScreen].bounds.size.width;
return width / 375.0;
}
#endif
3.第三种的屏幕适配是采用目前流行的Masonry 自动布局
这个推荐使用,并单独一篇博客介绍。
适合复杂cell里的控件布局和横竖屏的适配。
相关文章推荐
- ios7.2之后的警告汇总
- iOS block反向传值
- iOS黑魔法-Method Swizzling
- iOS - 监听键盘删除键之非代理实现
- [解析苹果官方文档]之[自动布局-view.autoresizingMask]
- iOS 视图控制器生命周期
- HDU 1017 A Mathematical Curiosity(枚举)
- iOS - cocoaPods
- iOS----JSON解析
- iOS程序猿之iOS绘图基础(draw)
- iOS沙盒机制
- IOS后台常驻,实现后台下载
- ios使用xib自定义view
- iOS 如何正确的绘制1像素的线
- iOS开发的几个奇葩问题
- 【iOS开发】打包静态库.a文件
- xcode崩溃时定位到出错行
- LayoutIfNeeded
- 查看ios7中的所有系统字体名字
- 将iOS中Safari 的默认搜索引擎由google.cn改为google.com的方法