zoukankan      html  css  js  c++  java
  • ios 在项目中使用文字ttf文件

    1.把test.ttf文件添加到工程中

    2.在info.plist中添加Fonts provided by application(数组类型),数组中添加item   test.ttf 

     ps:

    获取ttf字体名称

    法1.遍历所有字体名称找到对应的

        for( NSString *familyName in [UIFont familyNames] ){  
            NSLog( "Family: %s ", [familyName UTF8String] );  
            for( NSString *fontName in  [UIFont fontNamesForFamilyName:familyName] ){  
                NSLog( " Font: %s ", [fontName UTF8String] );  
            }  
        }

    法2.通过读取本地文件路径

       NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"ttf"];

        NSURL *fontUrl = [NSURL fileURLWithPath:path];

        CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)fontUrl);

        CGFontRef fontRef = CGFontCreateWithDataProvider(fontDataProvider);

        CGDataProviderRelease(fontDataProvider);

        CTFontManagerRegisterGraphicsFont(fontRef, NULL);

        NSString *fontName = CFBridgingRelease(CGFontCopyPostScriptName(fontRef));

        CGFontRelease(fontRef);

  • 相关阅读:
    TensorFlow设置GPU占用量
    与服务器同步工程(expect脚本)
    C/C++中#pragma once的使用
    sublime text 3 快捷键大全
    Sublime Text 3 注册码
    如何用diff比较两个文件夹下的内容
    Error in building opencv with ffmpeg
    opencv: Rotate image by 90, 180 or 270 degrees
    初识HTTPS
    Unity3D之Mecanim动画系统学习笔记(十一):高级功能应用
  • 原文地址:https://www.cnblogs.com/YuFly-lyx/p/8032554.html
Copyright © 2011-2022 走看看