iOS 添加自定义的字体 Fonts provided by application

在项目中应用漂亮的字体

1.第一步找到想用的字体的ttf格式,加入到工程的resource目录下



2.

在工程的plist中AddRow,“Fonts provided by application” ,然后添加key为item0,value为你刚才加入的testFont.ttf 。

是这样,可以添加多个,使用的时候写对应字体名字就行。

3.在你的工程就可以直接用了。xx.font = [UIFont fontWithName:@"testFont" size:20.0]

注意,在程序中先加入这段代码,运行:

[html]  view plain  copy
  1. NSArray *familyNames =[[NSArray alloc]initWithArray:[UIFont familyNames]];    
  2.    NSArray *fontNames;    
  3.    NSInteger indFamily, indFont;    
  4.    NSLog(@"[familyNames count]===%d",[familyNames count]);    
  5.    for(indFamily=0;indFamily<[familyNames count];++indFamily)    
  6.            
  7. {    
  8.     NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);    
  9.        fontNames =[[NSArray alloc]initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];    
  10.     
  11.     for(indFont=0; indFont<[fontNames count]; ++indFont)    
  12.                
  13.     {    
  14.         NSLog(@"Font name: %@",[fontNames objectAtIndex:indFont]);    
  15.                
  16.        }    
  17.            
  18.     [fontNames release];    
  19. }    
  20.        
  21. [familyNames release];  

查看console,以上程序会列出所有的字型,当然也包含“Fonts provided by application”所加的字型,但请注意,名字可能差距很大,要自己找一下

猜你喜欢

转载自blog.csdn.net/liu943367080/article/details/80626721