使用 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 上都测试过了亲.
附带本人的测试结果^_^
*用的时候直接取

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

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

再来一个组合显示:

结果,效果拔群!!

使用 UIFontWDCustomLoader 载入自定义字体的更多相关文章
- css3 自定义字体的使用方法
@font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体,你们当中或许有许 ...
- iOS - 使用自定义字体-苹方字体
苹方提供了六个字重,font-family 定义如下:苹方-简 常规体font-family: PingFangSC-Regular, sans-serif;苹方-简 极细体font-family: ...
- CSS 自定义字体
移动端如何兼容UI给的字体 [toc] 移动端的默认字体 IOS 默认中文字体是Heiti SC 默认英文字体是Helvetica 默认数字字体是HelveticaNeue Android 默认中文字 ...
- 【WP 8.1开发】如何把自定义字体塞进应用里
或许,系统自带的字体不足以体现应用程序的魅力,对于表现极强的汉字来说,更是如此.这时候,我们就会想,要是能把网上下载的艺术字体塞到应用包中,那岂不美哉?那么,这可以实现吗?答案是Yes的. 接下来,阿 ...
- CSS3 使用自定义字体
CSS3 @font-face 规则 在 CSS3 之前,web 设计师必须使用已在用户计算机上安装好的字体.通过 CSS3,web 设计师可以使用他们喜欢的任意字体.当您您找到或购买到希望使用的字体 ...
- iOS自定义字体
1.下载字体库,如:DINCond-Bold.otf 2.双击,在mac上安装 3.把下载的字体库拖入工程中: 4.配置info.plist文件 5.xib方式设置自定义字体:Font选Custom, ...
- css3之自定义字体
使用@font-face自定义字体 我们在浏览国外的一些个人网站时,总是可以发现一些非常个性的字体,比如
- TextView的一些高级应用(自定义字体、显示多种颜色、添加阴影)
1. 自定义字体可以使用setTypeface(Typeface)方法来设置文本框内文本的字体,而android的Typeface又使用TTF字体文件来设置字体所以,我们可以在程序中放入TTF字 ...
- 使用自定义字体 @font-face 小试
第一次了解到@font-face是小伙伴给我展示的功能 感觉奇妙的不得了 @font-face 是CSS3中的一个模块 使用它你就可以将你自定义的web字体 去实现一些奇妙的想法 首先先介绍 ...
随机推荐
- KAFKA随机产生JMX 端口指定的问题
https://blog.csdn.net/weixin_40209426/article/details/82217987
- (使用通过混淆+自己第三方保留成功混淆)AndroidStudio 混淆打包
原文:https://blog.csdn.net/mazhidong/article/details/64820838 AndroidStudio中的项目可以用compile的形式引入github上的 ...
- mysql热数据加载管理
5.6版本之后,提供了一个新特性来快速预热buffer_pool缓冲池.在my.cnf里面加入几个参数: innodb_buffer_pool_dump_at_shutdown = 1 --在关闭 ...
- 洛谷——P1023 税收与补贴问题
P1023 税收与补贴问题 题目背景 每样商品的价格越低,其销量就会相应增大.现已知某种商品的成本及其在若干价位上的销量(产品不会低于成本销售),并假设相邻价位间销量的变化是线性的且在价格高于给定的最 ...
- 不可不说的Java“锁”事
前言 Java提供了种类丰富的锁,每种锁因其特性的不同,在适当的场景下能够展现出非常高的效率.本文旨在对锁相关源码(本文中的源码来自JDK 8).使用场景进行举例,为读者介绍主流锁的知识点,以及不同的 ...
- Oracle 判断为空 all space
You can use trim on the column. where trim(product_type) is null The above is not DBMS-independent, ...
- 切换 NPM 镜像源
转载:快速切换NPM源 我们介绍过cnpmjs.org和淘宝 npm 两个 NPM 镜像.除此之外,还有一些国外的 NPM 镜像.不同地区访问不同的镜像速度可能有差异,因此有时候需要切换 NPM 镜像 ...
- [leetcode DP]91. Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- ELK收集openstack日志
1.安装jdk 每个openstack服务器需要安装jdk,我安装的版本jdk-7u71-linux-x64.rpm 2.安装.配置Elastic Search install https://dow ...
- LOJ P1155 双栈排序 二分图染色 图论
https://www.luogu.org/problem/show?pid=P1155 题解: https://www.byvoid.com/zhs/blog/noip2008-twostack 开 ...
