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里的控件布局和横竖屏的适配。

  • 相关阅读:
    谈谈Windows Wow64
    Windows x86 下的 静态代码混淆
    Android so 文件进阶<二> 从dlsym()源码看android 动态链接过程
    You should blog even if you have no readers
    android app启动过程
    Android so文件进阶 <一>
    AndroidStudio+ideasmali动态调试smali汇编
    32位进程注入64位进程
    What is Windows Clustering
    Delphi实用小function
  • 原文地址:https://www.cnblogs.com/LiuChengLi/p/5160717.html
Copyright © 2011-2022 走看看