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);

  • 相关阅读:
    关于CoreData的使用
    【转】向iOS开发者介绍C++(-)
    Storyboard里面的几种Segue区别及视图的切换:push,modal,popover,replace和custom
    【转】Object-C 多线程中锁的使用-NSLock
    写了半天的返回
    oracle 锁表问题
    LINQ的基本认识
    Oracle客户端配置
    REVERSE
    vchar2和nvchar2
  • 原文地址:https://www.cnblogs.com/YuFly-lyx/p/8032554.html
Copyright © 2011-2022 走看看