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就不上了,就上面的代码.

转载于:https://www.cnblogs.com/dianming/p/6689797.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值