iOS添加自訂自體 [UIFont fontWithName: size:]

來源:互聯網
上載者:User

1.添加對應的自體檔案(.ttf或.otf等)到工程目錄下,比如:SIMKAI.TTF

2.在-info.plist檔案中添加一項Fonts provided by application,item0對應的value為SIMKAI.TTF,多個自體依次添加即可。

3.使用 [UIFont fontWithName: size:]來設定自體,fontWithName的參數不一定是SIMKAI,這個字型名字需要別的方法去查。

查字型名字方法如下:

    for(NSString *familyName in [UIFont familyNames])    {           NSLog(@"familyName = %@", familyName);                for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName])        {               NSLog(@"\tfontName = %@", fontName);        }    }

在上面第2步添加前和添加後的情況下分別執行如上代碼,把控制台列印出的資訊分別做記錄。

控制台列印資訊樣本:

2012-08-08 14:27:56.150[1821:c07] familyName = Thonburi2012-08-08 14:27:56.153[1821:c07] fontName = Thonburi-Bold2012-08-08 14:27:56.154[1821:c07] fontName = Thonburi2012-08-08 14:27:56.154[1821:c07] familyName = Snell Roundhand2012-08-08 14:27:56.154[1821:c07] fontName = SnellRoundhand-Bold2012-08-08 14:27:56.155[1821:c07] fontName = SnellRoundhand-Black2012-08-08 14:27:56.155[1821:c07] fontName = SnellRoundhand2012-08-08 14:27:56.156[1821:c07] familyName = Academy Engraved LET2012-08-08 14:27:56.156[1821:c07] fontName = AcademyEngravedLetPlain2012-08-08 14:27:56.157[1821:c07] familyName = Marker Felt2012-08-08 14:27:56.157[1821:c07] fontName = MarkerFelt-Wide2012-08-08 14:27:56.158[1821:c07] fontName = MarkerFelt-Thin2012-08-08 14:27:56.158[1821:c07] familyName = Geeza Pro2012-08-08 14:27:56.159[1821:c07] fontName = GeezaPro-Bold2012-08-08 14:27:56.159[1821:c07] fontName = GeezaPro2012-08-08 14:27:56.182[1821:c07] familyName = Arial Rounded MT Bold2012-08-08 14:27:56.183[1821:c07] fontName = ArialRoundedMTBold2012-08-08 14:27:56.183[1821:c07] familyName = Trebuchet MS2012-08-08 14:27:56.184[1821:c07] fontName = TrebuchetMS2012-08-08 14:27:56.184[1821:c07] fontName = TrebuchetMS-Bold

用比較檔案的方法找出2次從控制台列印出的資訊的不同內容,這些不同的內容就是新添加進去的字型的名字。

從而可以看出,新添加進去的自體的名字就是 KaiTi_GB2312

設定自體的時候就應該如下操作:

[UIFont fontWithName:@"KaiTi_GB2312" size:20.0]

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.