iOS Developer

iOS9以前版本自定义字体

2017-01-19  本文已影响154人  Rijkaa

PingfangSC字体

添加字体

1.找到系统字体

spotlight搜索“字体册”,找到pingfangsc.ttc,移入项目并添加到project的copy bundle resources中。

找到字体库

2.给项目添加字体库

在info.plist的Fonts provided by application添加响应字体库名称,后缀也需要

添加字体库到项目

3.打印font family,检查是否安装成功

移入项目后使用代码查看项目中支持的字体

// 遍历获取字体名称
    for(NSString *fontFamilyName in [UIFont familyNames])
    {
        NSLog(@"family:'%@'",fontFamilyName);
        for(NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName])
        {
            NSLog(@"\tfont:'%@'",fontName);
        }
        NSLog(@"-------------");
    }
 line:163 content:-------------

 line:158 content:family:'PingFang SC'

 line:161 content:  font:'PingFangSC-Medium'

 line:161 content:  font:'PingFangSC-Regular'

 line:161 content:  font:'PingFangSC-Light'

 line:161 content:  font:'PingFangSC-Ultralight'

 line:161 content:  font:'PingFangSC-Semibold'

 line:161 content:  font:'PingFangSC-Thin'

 line:163 content:-------------

代码调用

//label.text
[depictLabel setFont:[UIFont fontWithName:@"PingFangSC-Regular" size:[Util getFontSizeFrom6:32]]];

//NSAttributedString
NSAttributedString *modifyCodeFieldAttributePlaceHolder = [[NSAttributedString alloc] initWithString:@"请输入验证码" attributes:@{NSForegroundColorAttributeName:[Util stringTOColor:@"#999999"],NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Regular" size:[Util getSizeFrom6:28]]}];
        _modifyCodeField.attributedPlaceholder = modifyCodeFieldAttributePlaceHolder;
        _modifyCodeField.font = [UIFont fontWithName:@"PingFangSC-Regular" size:[Util getSizeFrom6:28]];

Avenir字体

上一篇下一篇

猜你喜欢

热点阅读