zoukankan      html  css  js  c++  java
  • 使用 UIFontWDCustomLoader 载入自定义字体

    UIFontWDCustomLoader

    https://github.com/daktales/UIFontWDCustomLoader

    You can use UIFontWDCustomLoader category to load any compatible font into your iOS projects at runtime without messing with plist, font unknown names or strange magic.

    The only things you'll have to know are your font filenames and this library name.

    You can also use this library to load new fonts after app installation.

    还记得你之前怎么将一个字体载入到 iOS 中的吗?设置plist文件,找字体真实的名字等等,各种匹配不上,显示不出效果想杀人对吧.哥今天就给你带来了一个 UIFont 的类目文件,它可以在 iOS 运行的时候动态载入你想要的字体,知不知道字体名字没关系,哥的类目知道.

    你唯一需要知道的就是,你拖到工程中字体的名字,以及哥这个类目的名字.

    当然,如果你的应用已经安装了,但是,你还是能够在安装后读取下载的字体的.

    Using font(使用字体)

    #import "UIFont+WDCustomLoader.h"
    

    One time setup (Explicit registration):(一次设定,明确的注册)

    /* FONT COLLECTION FILE (TTC OR OTC) */
    
    // Create an NSURL for your font file: 'Lao MN.ttc'
    NSURL *laoFontURL = [[NSBundle mainBundle] URLForResource:@"Lao MN" withExtension:@"ttc"]];
    
    // Do the registration.
    NSArray *fontPostScriptNames = [UIFont registerFontFromURL:laoFontURL];
    
    // If everything went ok, fontPostScriptNames will become @[@"LaoMN",@"LaoMN-Bold"] 
    // and collection will be registered.
    // (Note: On iOS < 7.0 you will get an empty array)
    
    // Then, anywhere in your code, you can do
    UIFont *laoFont = [UIFont fontWithName:@"LaoMN" size:18.0f];
    

    or

    /* SINGLE FONT FILE (TTF OR OTF) */
    
    // Create an NSURL for your font file: 'Lato-Hairline.ttf'
    NSURL *latoHairlineFontURL = [[NSBundle mainBundle] URLForResource:@"Lato-Hairline" withExtension:@"ttf"]];
    
    // Do the registration.
    NSArray *fontPostScriptNames = [UIFont registerFontFromURL:latoHairlineFontURL];
    
    // If everything went ok, fontPostScriptNames will become @[@"Lato-Hairline"] 
    // and collection will be registered.
    
    // Then, anywhere in your code, you can do
    UIFont *latoHairlineFont = [UIFont fontWithName:@"Lato-Hairline" size:18.0f];
    
    // or
    UIFont *latoHairlineFont = [UIFont customFontWithURL:latoHairlineFontURL size:18.0f];
    
    // or (*deprecated*)
    UIFont *myCustomFont = [UIFont customFontOfSize:18.0f withName:@"Lato-Hairline" withExtension:@"ttf"];
    

    No setup (Implicit registration)(不用设置,使用时注册)

    /* SINGLE FONT (TTF OR OTF) */
    
    // Create an NSURL for your font file: 'Lato-Hairline.ttf'
    NSURL *latoHairlineFontURL = [[NSBundle mainBundle] URLForResource:@"Lato-Hairline" withExtension:@"ttf"]];
    
    // Then, anywhere in your code, you can do
    UIFont *latoHairlineFont = [UIFont customFontWithURL:latoHairlineFontURL size:18.0f];
    
    // or (*deprecated*)
    UIFont *myCustomFont = [UIFont customFontOfSize:18.0f withName:@"Lato-Hairline" withExtension:@"ttf"];
    

    NOTE: Font registration will be made on first [ UIFont customFont… ] method call.

    注意:你在注册字体前,需要先调用[UIFont customFont...]方法.

    Prerequisites(前提条件)

    UIFontWDCustomLoader requires:

    • ARC
    • Deployment target greater or equal to iOS 4.1
    • CoreText Framework
    • 需要ARC
    • >= iOS 4.1
    • 需要引入CoreText框架

    This library has been tested with: iOS 5, 6 and 7

    在 iOS 5,6,7 上都测试过了亲.

    附带本人的测试结果^_^

    *用的时候直接取

    *仅注册一次,以后可以直接根据名字使用

    上述两种方式都得出了一样的结果哦,亲.

    再来一个组合显示:

    结果,效果拔群!!

  • 相关阅读:
    ecshop 调用指定分类的推荐,热卖,新品
    ecshop 首页调用指定类产品
    html常用笔记
    ecshop 修改flash图片大小
    ecshop 删除随机版权
    Java Web(一) Servlet详解!!
    Git使用总结
    git clone命令使用
    Lucene学习总结之四:Lucene索引过程分析
    Lucene学习总结之二:Lucene的总体架构
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3656900.html
Copyright © 2011-2022 走看看