iOS - 外加字体(只需三步-教你轻松实现)

时间:2022-03-05 15:42:00

外加字体

1.首先info.plist中加入属性Fonts provided by application,在item 0 处填写导入的ttf文件名

eg:

<key>UIAppFonts</key>

<array>

<string>方正兰亭纤黑简体.TTF</string>

<string>FZXQJW_0.TTF</string>

<string>CODE LIGHT.OTF</string>

<string>CODE BOLD.OTF</string>

<string>逐浪细阁体.otf</string>

</array>

然后在TAGECT中导入字体关联Compile Source

 

2.查出你导入字体的font name   

NSArray * fontArrays = [[NSArray alloc] initWithArray:[UIFont familyNames]];
    for (NSString * temp in fontArrays) {
        NSLog(@"Font name  = %@", temp);
    }


3.就是这样简单的用了呗

    UILabel * tempTwoLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 40)];
    UIFont * fontTwo = [UIFont fontWithName:@"DFPWaWaW5-GB" size:15];
    [tempTwoLabel setFont:fontTwo];
    [tempTwoLabel setText:@"这是新字体——ONe----->华康娃娃体"];
    [self.view addSubview:tempTwoLabel]