zoukankan      html  css  js  c++  java
  • 屏幕适配


    • 目的:为了能够使应用的显示以黄金比例运行在各个类型的苹果手机上。

    1、将以下代码放入 .pch 预编译文件中。

    
    #ifndef ScreenAdaptation_pch
    #define ScreenAdaptation_pch
    
    /************ 机子屏幕高度与宽度 *****************************/
    #define CHScreenH [UIScreen mainScreen].bounds.size.height
    #define CHScreenW [UIScreen mainScreen].bounds.size.width
    
    /****** 屏幕适配,以iphone 6 Plus 为基准 **************/
    #define HEIGHT_BASE 736
    #define WIDTH_BASE  414
    
    /******** 点适配 ********/
    #define ScaleH(HEIGHT) CHScreenH / HEIGHT_BASE * HEIGHT
    #define ScaleW(WIDTH)  CHScreenW / WIDTH_BASE * WIDTH
    /******** 字体适配 ********/
    #define ScaleFront(front)  CHScreenH / HEIGHT_BASE * front
    
    #endif /* ScreenAdaptation_pch */
    
    

    2、开始使用

    • 2.1 UIView的使用

        UIView *view = [[UIView alloc] init];
        view.frame = CGRectMake(ScaleW(10), ScaleH(10), CHScreenW - ScaleW(20), 0.5 * CHScreenH - ScaleH(20));
        view.backgroundColor = [UIColor redColor];
        NSLog(@"%f-----%f", ScaleW(10), ScaleH(10));
        [self.view addSubview:view];
    
    • 2.2 字体大小的使用

    UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(ScaleW(10), 0.5 * CHScreenH + ScaleH(10), CHScreenW - ScaleW(20), 0.5 * CHScreenH - ScaleH(20));
        label.text = @"屏幕字体适配呵呵呵";
        label.textAlignment = NSTextAlignmentCenter;
        [label setFont:[UIFont systemFontOfSize:ScaleFront(40)]];
        [self.view addSubview:label];
    

    3、码云地址

    4、效果图

    • 大屏幕iphone 6 Plus

    • 小屏幕iphone 5s

  • 相关阅读:
    Java-使用IO流对大文件进行分割和分割后的合并
    Java-单向链表算法
    Java-二分查找算法
    Java-二叉树算法
    Java-对象比较器
    Android中Activity的四种开发模式
    Struts2工作原理
    C++实现单例模式
    数组中有一个数字出现的次数超过数组的一半,请找出这个数字
    c++ enum用法【转】
  • 原文地址:https://www.cnblogs.com/CH520/p/9260053.html
Copyright © 2011-2022 走看看