系統(tǒng)用法一
- 通常我們會用
//設(shè)置字體樣式
numlable.font=[UIFont fontWithName:@"Arial" size:16.0];
//name參數(shù)如何獲取呢?
- 如何獲取字體名稱:
//方法
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)嵌。
具體步驟也很簡單:
- 將ttf文件拖入項目中;
- 修改plist文件,加入Fonts provided by application 配置,后面填上拖進來的項目名
4. 動態(tài)字體
參考唐巧先生的博客有比較詳細的介紹:http://blog.devtang.com/blog/2013/08/11/ios-asian-font-download-introduction/