iOS項目中設(shè)置各種字體

系統(tǒng)用法一

    1. 通常我們會用
//設(shè)置字體樣式
numlable.font=[UIFont fontWithName:@"Arial" size:16.0];
//name參數(shù)如何獲取呢?
    1. 如何獲取字體名稱:
//方法
NSArray *familyNames = [UIFont familyNames];
for(NSString *familyName in familyNames){
    NSLog(@"Family: %@",familyName);
    NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
    for( NSString *fontName in fontNames ){
        NSLog(@"Font: %@",fontName);
    }
}
  • 重點:上述代碼中這些里面就有很炫的字體,但是全部是只針對英文數(shù)字,對中文無效

系統(tǒng)用法二(沒用過)

  • 通過字體詳細字典對字體屬性進行設(shè)置
//UIFontDescriptorFamilyAttribute:設(shè)置字體家族
//UIFontDescriptorNameAttribute  :設(shè)置字體的字體名
//UIFontDescriptorSizeAttribute  :設(shè)置字體尺寸
//UIFontDescriptorMatrixAttribute:設(shè)置字體形變
UIFontDescriptor *attributeFontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:@{UIFontDescriptorFamilyAttribute: @"Marion", UIFontDescriptorNameAttribute:@"Marion-Regular",
UIFontDescriptorSizeAttribute: @40.0,
UIFontDescriptorMatrixAttribute:[NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(M_1_PI*1.5)]}];
 fnotLabel.font = [UIFont fontWithDescriptor:attributeFontDescriptor size:0.0];

3. 外界字體引入項目

如果想是中文有效,就需要我們自己導入三方庫了。具體方法請參考:http://www.cocoachina.com/ios/20150812/12938.html

現(xiàn)在網(wǎng)上不管是windows字體,還是Android字體只要是ttf格式的,或者是蘋果提供的ttc、otf格式,一般iOS程序都支持內(nèi)嵌。
具體步驟也很簡單:

    1. 將ttf文件拖入項目中;
    1. 修改plist文件,加入Fonts provided by application 配置,后面填上拖進來的項目名

4. 動態(tài)字體

參考唐巧先生的博客有比較詳細的介紹:http://blog.devtang.com/blog/2013/08/11/ios-asian-font-download-introduction/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容