zoukankan      html  css  js  c++  java
  • iOS 应用文字大小随系统文字大小改变

    转载请注明出处!!!

    如题,今天突发奇想,在iPhone中如果系统文字大小改变后,应用内文字大小会不会跟随变化。于是我就进行了实验。在设置中改变了文字大小之后,我发现基本上大部分的APP(系统除外)都不会跟随改变。(如美团、饿了么、淘宝、支付宝等)

    只有微信提示是否更换大小(微信内置了更改文字大小),QQ大部分跟随系统改变。

    那么它是如何做到的?

    我发现可以根据一个iOS10新特性来实现这个功能。

    下面贴代码,用代码说话:

     UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 200, 100)];
        myLabel.text = @"测试,金蝶鸡MMIFMIIRFMIMIRIFMI";
        // 设置文字字体跟随
        myLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
        // 设置字体大小可以改变
        myLabel.adjustsFontForContentSizeCategory = YES;
        myLabel.numberOfLines = 0;
        myLabel.backgroundColor = [UIColor redColor];
        [self.view addSubview:myLabel];
        
        UIButton *MyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        MyButton.frame = CGRectMake(100, 350, 100, 100);
        [MyButton setTitle:@"测试" forState:UIControlStateNormal];
        MyButton.backgroundColor = [UIColor blueColor];
        MyButton.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
        MyButton.titleLabel.adjustsFontForContentSizeCategory = YES;
        [self.view addSubview:MyButton];
        
        UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(250, 350, 200, 100)];
        textView.backgroundColor = [UIColor orangeColor];
        textView.text = @"交分解诶偶记对将诶偶家的饥饿哦,djiejijd eij dijeiji";
        textView.font =[UIFont preferredFontForTextStyle:UIFontTextStyleBody];
        textView.adjustsFontForContentSizeCategory = YES;
        [self.view addSubview:textView];
    
  • 相关阅读:
    leetcode 14. 最长公共前缀
    leetcode13. 罗马数字转整数
    leetcode 21.合并两个有序链表
    leetcode14-最长公共前缀
    leetcode13-罗马数字转整数
    leetcode11- 盛最多水的容器
    leetcode9-回文数
    leetcode7- 整数反转
    leetcode 1-两数之和
    文件的上传
  • 原文地址:https://www.cnblogs.com/weicyNo-1/p/8708986.html
Copyright © 2011-2022 走看看