美文网首页
iOS自定义字体

iOS自定义字体

作者: Maggie的小蜗居 | 来源:发表于2017-02-15 13:45 被阅读62次

    在开发中,经常需要不同的字体,让我们的app显得有个性化点,那怎么样去自定义字体呢?

    字体查询地址:https://fonts.google.com/

    1.下载需要的字体ttf文件,导入工程

    在Info.plist中添加一项:Fonts provided by application,填写字体文件名称加后缀.

    1.png

    2.前往target -> build phases -> Copy Bundle resources 把字体文件Add进来

    2.png

    3. 打印出所以字体对应的名字

     - (void)fonts
    {
        NSArray *familyNames = [UIFont familyNames];
        for( NSString *familyName in familyNames )
        {
            NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
            for( NSString *fontName in fontNames )
            {
                printf( "\tFont: %s \n", [fontName UTF8String] );
            }
        }
    
    }
    

    4. 使用name自定义字体

    - (void)buildLabel
    {
        self.firstLabel = [[UILabel alloc] init];
        self.firstLabel.text = @"我哈尼哦搭讪ddd风的地方";
        self.firstLabel.font = [UIFont fontWithName:@"OpenSans" size:30];
        [self.view addSubview:self.firstLabel];
        self.firstLabel.frame = CGRectMake(10, 100, 380, 30);
        
        self.secondLabel = [[UILabel alloc] init];
        self.secondLabel.text = @"我哈尼哦搭讪ddd风的地方";
        [self.view addSubview:self.secondLabel];
        self.secondLabel.font = [UIFont fontWithName:@"OpenSans-Italic" size:20];
        self.secondLabel.frame = CGRectMake(10, 160, 260, 30);
    
    }
    
    2.png

    相关文章

      网友评论

          本文标题:iOS自定义字体

          本文链接:https://www.haomeiwen.com/subject/rvrqwttx.html