码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 添加ttf字体

时间:2016-05-12 23:32:28      阅读:1023      评论:0      收藏:0      [点我收藏+]

标签:

在开发的过程中,有时Xcode提供的字体不能满足我们的需求,所以我们需要添加其他的第三方字体。
提供一个字体下载的地址:找字体

效果图

第一页是Swift代码使用第三方字体,第二页是OC使用第三方字体。
技术分享

集成过程

1.下载.ttf字体

先下载.ttf字体,把字体拖进项目。
技术分享

2.在Info.plist里增加Fonts provided by application

技术分享
或是在Info.plist的源码里面增加下面的代码:

<key>UIAppFonts</key>
    <array>
        <string>Amano.ttf</string>
        <string>Amelia BT.ttf</string>
        <string>Wzk.ttf</string>
    </array>

3.在Swift代码里面使用

let testLabel = UILabel.init(frame: CGRectMake(100, 120, 120, 50))
testLabel.font = UIFont.init(name: "woziku-bsdsm-CN4262", size: 20)
testLabel.text = "湖工电气"
testLabel.textAlignment = NSTextAlignment.Center
testLabel.backgroundColor = UIColor.orangeColor()
self.view.addSubview(testLabel)

4.在OC代码里面使用

self.showLabel.font = [UIFont fontWithName:@"woziku-bsdsm-CN4262" size:18];
self.showLabel.text = @"湖工电气";

5.在IB里面使用

技术分享

6.查看Xcode里面的字体

// 打印字体
let fonts = UIFont.familyNames()
print(fonts)

在打印结果里面,我们就可以看见我们添加进来的三中字体:Amano,Amelia BT和woziku-bsdsm-CN4262。

["Copperplate", "Heiti SC", "Iowan Old Style", "Kohinoor Telugu", "Courier New", "Heiti TC", "Gill Sans", "Apple SD Gothic Neo", "woziku-bsdsm-CN4262", "Marker Felt", "Thonburi", "Avenir Next Condensed", "Tamil Sangam MN", "Helvetica Neue", "Gurmukhi MN", "Times New Roman", "Georgia", "Apple Color Emoji", "Arial Rounded MT Bold", "Kailasa", "Kohinoor Devanagari", "Kohinoor Bangla", "Chalkboard SE", "Sinhala Sangam MN", "PingFang TC", "Gujarati Sangam MN", "Damascus", "Noteworthy", "Geeza Pro", "Avenir", "Academy Engraved LET", "Mishafi", "Futura", "Farah", "Kannada Sangam MN", "Arial Hebrew", "Arial", "Party LET", "Chalkduster", "Hoefler Text", "Optima", "Palatino", "Lao Sangam MN", "Malayalam Sangam MN", "Al Nile", "Bradley Hand", "PingFang HK", "Trebuchet MS", "Helvetica", "Courier", "Cochin", "Amano", "Amelia BT", "Devanagari Sangam MN", "Oriya Sangam MN", "Hiragino Mincho ProN", "Snell Roundhand", "Zapf Dingbats", "Bodoni 72", "Verdana", "American Typewriter", "Avenir Next", "Baskerville", "Khmer Sangam MN", "Didot", "Savoye LET", "Bodoni Ornaments", "Symbol", "Menlo", "Bodoni 72 Smallcaps", "Papyrus", "Hiragino Sans", "PingFang SC", "Euphemia UCAS", "Telugu Sangam MN", "Bangla Sangam MN", "Zapfino", "Bodoni 72 Oldstyle"]

总结

集成和使用第三方字体,没有上面困难,按照相应的步骤操作就可以。有一点需要注意的:字体文件的名字不一定是字体库的名字。我们我们需要打印Xcode里面的字体库,查看我们的字体库的名字。上面的项目文件结构里面查看的字体库的文件名和代码里面使用的字库:woziku-bsdsm-CN4262就是很好的说明。
代码下载地址:Swift-Font

iOS 添加ttf字体

标签:

原文地址:http://blog.csdn.net/zhuming3834/article/details/51346288

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!