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 上都测试过了亲.

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

*用的时候直接取

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

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

再来一个组合显示:

结果,效果拔群!!

使用 UIFontWDCustomLoader 载入自定义字体的更多相关文章

  1. css3 自定义字体的使用方法

    @font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体,你们当中或许有许 ...

  2. iOS - 使用自定义字体-苹方字体

    苹方提供了六个字重,font-family 定义如下:苹方-简 常规体font-family: PingFangSC-Regular, sans-serif;苹方-简 极细体font-family: ...

  3. CSS 自定义字体

    移动端如何兼容UI给的字体 [toc] 移动端的默认字体 IOS 默认中文字体是Heiti SC 默认英文字体是Helvetica 默认数字字体是HelveticaNeue Android 默认中文字 ...

  4. 【WP 8.1开发】如何把自定义字体塞进应用里

    或许,系统自带的字体不足以体现应用程序的魅力,对于表现极强的汉字来说,更是如此.这时候,我们就会想,要是能把网上下载的艺术字体塞到应用包中,那岂不美哉?那么,这可以实现吗?答案是Yes的. 接下来,阿 ...

  5. CSS3 使用自定义字体

    CSS3 @font-face 规则 在 CSS3 之前,web 设计师必须使用已在用户计算机上安装好的字体.通过 CSS3,web 设计师可以使用他们喜欢的任意字体.当您您找到或购买到希望使用的字体 ...

  6. iOS自定义字体

    1.下载字体库,如:DINCond-Bold.otf 2.双击,在mac上安装 3.把下载的字体库拖入工程中: 4.配置info.plist文件 5.xib方式设置自定义字体:Font选Custom, ...

  7. css3之自定义字体

    使用@font-face自定义字体 我们在浏览国外的一些个人网站时,总是可以发现一些非常个性的字体,比如

  8. TextView的一些高级应用(自定义字体、显示多种颜色、添加阴影)

    1.    自定义字体可以使用setTypeface(Typeface)方法来设置文本框内文本的字体,而android的Typeface又使用TTF字体文件来设置字体所以,我们可以在程序中放入TTF字 ...

  9. 使用自定义字体 @font-face 小试

    第一次了解到@font-face是小伙伴给我展示的功能  感觉奇妙的不得了    @font-face 是CSS3中的一个模块  使用它你就可以将你自定义的web字体 去实现一些奇妙的想法 首先先介绍 ...

随机推荐

  1. C#连接SQL Server数据库小贴士

    在较低版本vs中需要添加using system.data.sqlClient; 在新版本vs中需要写成using System.Data.SqlClient; 作者:耑新新,发布于  博客园 转载请 ...

  2. 微信小程序-视频教程-百度云-下载

    链接: https://pan.baidu.com/s/16WGL3whutozx-UXqsDPhhA 提取码: 关注公众号[GitHubCN]回复获取   什么是微信小程序?小程序是一种不需要下载安 ...

  3. Android Studio3.x新的依赖方式(implementation、api、compileOnly)

    https://blog.csdn.net/yuzhiqiang_1993/article/details/78366985?locationNum=6&fps=1 Android Studi ...

  4. 【HackerRank】How Many Substrings?

    https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...

  5. 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest B - Bring Your Own Bombs 离散化+扫描线+计算期望

    扫描线一边扫一边算期望,细节比较多. #include<bits/stdc++.h> #define LL long long #define fi first #define se se ...

  6. 【解决】 64位笔记本丢失 MSVCR110.dll win10 phpstudy2017

    启动程序报错如下: 无法启动此程序,因为计算机中丢失MSVCR110.dll.尝试重新安装该程序以解决此问题. 应该很容易就搜索到,缺少这样的dll文件,是没有安装Visual C++ Redistr ...

  7. 《Android源码设计模式》--策略模式

    No1: 定义:策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化. No2: 使用场景: 1)针对同一类型问题的多种处理方式,仅 ...

  8. linux config

    1.自定义命令:.bashrc 文件添加自定义命令 2.完成后,命令:source . .bashrc  使配置的自定义命令生效,如果提示没有该命令的情况,用   . .bashrc (注意是2个“点 ...

  9. Spring boot之SpringApplicationBuilder,@@Configuration注解,@Component注解

    SpringApplicationBuilder: 该方法的作用是可以把项目打包成war包 需要配置启动类,pom.xml文件等,具体见:http://blog.csdn.net/linzhiqian ...

  10. 二、redis系列之持久化

    1. 绪言 redis是一种内存数据库,它把数据存储在服务器的内存当中,这样极大地保证了redis数据库的性能,但也为数据安全带来了隐患——redis所在服务器重启或者发生宕机后,redis数据库里的 ...