zoukankan      html  css  js  c++  java
  • iOS 如何使用第三方字库

    1.第一步找到你想用的字体的 ttf 格式。加入到你的工程的resouce目录下。

    2.在工程的plist中AddRow,“Fonts provided by application” ,然后添加key为item0,value为你刚才加入的testFont.ttf 。

    是这样,可以添加多个,使用的时候写对应字体名字就行。

    3.在你的工程就可以直接用了。xx.font = [UIFont fontWithName:@"testFont" size:20.0];

     
     
    但是一般来说,字体文件比较大,不该内置,而且如果都用plist预定义的方式,那肯定就没法覆盖全,导致用户不能使用更多自己喜欢的字体。所以应该用代码读取字体的方式:
     
    提供字体文件路径,返回所需要字体:
     
    复制代码
     

    添加CoreText字库   导入#import "CoreText/CoreText.h"头文件

    -(UIFont*)customFontWithPath:(NSString*)path size:(CGFloat)size
    {
        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));
        UIFont *font = [UIFont fontWithName:fontName size:size];
        CGFontRelease(fontRef);
        return font;
    }
  • 相关阅读:
    Git常用操作命令
    android快速入门
    使用Jsoup 抓取页面的数据
    js面向对象组件
    js事件详解
    图解TCP-IP协议
    error: linking with `cc` failed: exit code: 1
    git——'fatal: cannot do a partial commit during a merge'
    git add 而未 commit 的文件丢失后找回
    为rust配置国内/科大源
  • 原文地址:https://www.cnblogs.com/woaixixi/p/5590426.html
Copyright © 2011-2022 走看看