使用 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字体 去实现一些奇妙的想法 首先先介绍 ...
随机推荐
- javascript重要类方法笔记
三.数据结构和map 1.大括号数据结构:{} 1.1 键值对形式,类似Map 1.2 var treeNode={}; treeNode ...
- 《HBase实战》学习笔记
第二章 入门 HBase写路径: 增加新行和修改已有的行,内部机制是一样的. 写入的时候,会写到预写日志(WAL)和MemStore中. MenmStore是内存里的写入缓冲区.填满后,会将数据刷写 ...
- USACO 5.1 Fencing the Cows
Fencing the CowsHal Burch Farmer John wishes to build a fence to contain his cows, but he's a bit sh ...
- BZOJ 1036: [ZJOI2008]树的统计Count (树链剖分模板题)
1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 14982 Solved: 6081[Submit ...
- git status中文文件名编码问题解决
在默认设置下,中文文件名在工作区状态输出,中文名不能正确显示,而是显示为八进制的字符编码. 通过将git配置变量 core.quotepath 设置为false,就可以解决中文文件名称在这些Git命令 ...
- Loadrunner参数化逗号报错解决方法
Loadrunner参数化逗号报错解决方法 介绍Loadrunner参数化时,参数中包含有逗号时出错的解决方法. 在Loadrunner进行参数化时,参数中如果含有逗号,编辑保存后会报错: 此 ...
- js回到顶部 动画速度 (自己记录)
x=x-20; 设置回到每10s的速度, function gotoTop(){ var x=document.body.scrollTop||document.documentElement.scr ...
- Android手机系统设置页面跳转
android.provider.Settings. 1. ACTION_ACCESSIBILITY_SETTINGS : // 跳转系统的辅助功能界面 Intent intent = ne ...
- 【基础知识】ASP.NET[基础二(aspx)]
1.cs可以调用aspx中的runat=server控件,aspx中也可以访问测试中定义的字段.函数,还可以编写复杂的C#代码,for等所有C#代码都可以写在aspx中(不推荐这样写): 2.把代码写 ...
- python opencv3 矩形 圆形边框
git:https://github.com/linyi0604/Computer-Vision # coding:utf8 import cv2 import numpy as np # 读入图像 ...
