iOS 添加ttf字型

來源:互聯網
上載者:User

標籤:

在開發的過程中,有時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.CentertestLabel.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字型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.