标签:
在开发的过程中,有时Xcode提供的字体不能满足我们的需求,所以我们需要添加其他的第三方字体。
提供一个字体下载的地址:找字体。
第一页是Swift代码使用第三方字体,第二页是OC使用第三方字体。
先下载.ttf字体,把字体拖进项目。
或是在Info.plist的源码里面增加下面的代码:
<key>UIAppFonts</key>
<array>
<string>Amano.ttf</string>
<string>Amelia BT.ttf</string>
<string>Wzk.ttf</string>
</array>
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)
self.showLabel.font = [UIFont fontWithName:@"woziku-bsdsm-CN4262" size:18];
self.showLabel.text = @"湖工电气";
// 打印字体
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。
标签:
原文地址:http://blog.csdn.net/zhuming3834/article/details/51346288