IOS中得系统字体

Phone上的系统字体在很多场合都可以满足要求了。你可以通过系统提供的字体类方法轻松地在普通、加粗和斜体之间选择。示例代码如下:


UIFont *mainTitleFont = [UIFont boldSystemFontOfSize:14.0]; 
UIFont *subTitleFont = [UIFont SystemFontOfSize:14.0]; 
UIFont *textFont = [UIFont italicSystemFontOfSize:12.0];  

 

 

 

但如果要一个加粗斜体或者其他字体怎么办呢?在这种情况下,你可以按如下使用fontWithName方法:  

UIFont *altFont = [UIFont fontWithName:@"Courier-Bold" size:14.0];

 

 

这很好,不过你如何知道可用的字体名字呢?如果你猜错了字体名字,你的代码会抛出异常——这里可没有映射到最接近字体的优雅处理!

在iPhone文档上我无法找到可用的字体名字,在网络上搜索的时候也无果(至少在搜索结果的前几页)。所以我写了如下一段代码:  

  // 列出iPhone上所有的字体    // List all fonts on iPhone
  NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
  NSArray *fontNames;
  NSInteger indFamily, indFont;
  for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
  {
      NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
      fontNames = [[NSArray alloc] initWithArray:
          [UIFont fontNamesForFamilyName:
          [familyNames objectAtIndex:indFamily]]];
      for (indFont=0; indFont<[fontNames count]; ++indFont)
      {
          NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
      }
      [fontNames release];
  }
  [familyNames release];

 

如果使用iPhone SDK v2.1输出结果如下: 
Family name: Hiragino Kaku Gothic ProN W3
    Font name: HiraKakuProN-W3
Family name: Courier
    Font name: Courier
    Font name: Courier-BoldOblique
    Font name: Courier-Oblique
    Font name: Courier-Bold
Family name: Arial
    Font name: ArialMT
    Font name: Arial-BoldMT
    Font name: Arial-BoldItalicMT
    Font name: Arial-ItalicMT
Family name: STHeiti TC
    Font name: STHeitiTC-Light
    Font name: STHeitiTC-Medium
Family name: AppleGothic
    Font name: AppleGothic
Family name: Courier New
    Font name: CourierNewPS-BoldMT
    Font name: CourierNewPS-ItalicMT
    Font name: CourierNewPS-BoldItalicMT
    Font name: CourierNewPSMT
Family name: Zapfino
    Font name: Zapfino
Family name: Hiragino Kaku Gothic ProN W6
    Font name: HiraKakuProN-W6
Family name: Arial Unicode MS
    Font name: ArialUnicodeMS
Family name: STHeiti SC
    Font name: STHeitiSC-Medium
    Font name: STHeitiSC-Light
Family name: American Typewriter
    Font name: AmericanTypewriter
    Font name: AmericanTypewriter-Bold
Family name: Helvetica
    Font name: Helvetica-Oblique
    Font name: Helvetica-BoldOblique
    Font name: Helvetica
    Font name: Helvetica-Bold
Family name: Marker Felt
    Font name: MarkerFelt-Thin
Family name: Helvetica Neue
    Font name: HelveticaNeue
    Font name: HelveticaNeue-Bold
Family name: DB LCD Temp
    Font name: DBLCDTempBlack
Family name: Verdana
    Font name: Verdana-Bold
    Font name: Verdana-BoldItalic
    Font name: Verdana
    Font name: Verdana-Italic
Family name: Times New Roman
    Font name: TimesNewRomanPSMT
    Font name: TimesNewRomanPS-BoldMT
    Font name: TimesNewRomanPS-BoldItalicMT
    Font name: TimesNewRomanPS-ItalicMT
Family name: Georgia
    Font name: Georgia-Bold
    Font name: Georgia
    Font name: Georgia-BoldItalic
    Font name: Georgia-Italic
Family name: STHeiti J
    Font name: STHeitiJ-Medium
    Font name: STHeitiJ-Light
Family name: Arial Rounded MT Bold
    Font name: ArialRoundedMTBold
Family name: Trebuchet MS
    Font name: TrebuchetMS-Italic
    Font name: TrebuchetMS
    Font name: Trebuchet-BoldItalic
    Font name: TrebuchetMS-Bold
Family name: STHeiti K
    Font name: STHeitiK-Medium
    Font name: STHeitiK-Light

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值