zoukankan      html  css  js  c++  java
  • iOS开发——屏幕尺寸适配

    对于屏幕尺寸适配,目前先指竖屏的方式适合方式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里的控件布局和横竖屏的适配。

  • 相关阅读:
    Jmeter基础元件
    Jmeter性能测试之添加思考时间
    Jmeter断言实例—响应断言
    Jmeter调试脚本之断言
    Jmeter调试脚本之关联
    jmeter调试脚本之变量参数化
    jmeter调试脚本之用户自定义变量
    XAMPP中Apache和Mysql启动失败问题总结
    Jmeter运行badboy录制的脚本
    Bugfree安装与使用
  • 原文地址:https://www.cnblogs.com/LiuChengLi/p/5160717.html
Copyright © 2011-2022 走看看