• iOS-Runtime字体适配


    你还在为适配字体大小发愁?  看这里:

    #define MyUIScreen  375  //UI设计原型图的手机尺寸宽度(6), 6p的--414
    
    @implementation UIFont (Runtime)
    
    +(void)load
    {
        Method method = class_getClassMethod([self class], @selector(systemFontOfSize:));
        
        Method MyMethod = class_getClassMethod([self class], @selector(adapterFontOfSize:));
        
        method_exchangeImplementations(method, MyMethod);
    }
    
    +(UIFont *)adapterFontOfSize:(CGFloat)fontSize
    {
        return [UIFont adapterFontOfSize:fontSize * [UIScreen mainScreen].bounds.size.width /MyUIScreen];
    }

    正常调用就行了:

        
        UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 150, [UIScreen mainScreen].bounds.size.width, 60)];
        label.text = @"适配字体大小";
        label.backgroundColor = [UIColor yellowColor];
        label.font = [UIFont systemFontOfSize:16];
        [self.view addSubview:label];

    我不信!  不信你可以试试.

    Demo就不上了,就上面的代码.

  • 相关阅读:
    nginx日志、变量
    http相关
    nginx.conf文件的使用
    NA交换①
    第一章 何为网络
    第二章 以太网
    SATA、SCSI、SAS
    第十章 安全
    附录A 思科互联网络操作系统(IOS)
    标准ACL、扩展ACL和命名ACL的配置详解
  • 原文地址:https://www.cnblogs.com/dianming/p/6689797.html
Copyright © 2020-2023  润新知