【问题标题】:Which fonts are available on iOS 4.2?iOS 4.2 上可以使用哪些字体?
【发布时间】:2011-05-12 13:00:22
【问题描述】:

我正在寻找 iOS 4.2 上可用字体的官方列表,因为 Apple 在 4.2 更新中包含了更多字体。

不幸的是,我似乎在主文档中找不到任何东西,在 Apple 的开发者网站上也找不到;但我依稀记得在某处我看到了一个“官方”,也就是苹果列出的iOS上所有可用字体的列表。

如果有人能指点我一份文档,那就太好了。 :)

提前致谢!

更新:

在 App Store 上找到了一款名为“字体”的应用(免费)。它只是显示设备上的所有字体。

【问题讨论】:

标签: iphone ipad fonts ios4


【解决方案1】:

您可以使用此方法检查您的设备(iPhone 或 iPad)的可用字体

- (void)getAllFonts{
   NSArray *fontFamilies =[UIFont familyNames];

   for(int i =0; i <[fontFamilies count]; i++){
       NSString *fontFamily =[fontFamilies objectAtIndex:i];
       NSArray *fontNames =[UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
       NSLog(@"%@: %@", fontFamily, fontNames);
   }
}

复制/粘贴到一个类上并使用 [self getAllFonts];

该列表应显示在您的日志中

编辑:如果你想看看它是什么样子,我们使用表格视图怎么样

第 1 步:将其添加到您的标题中

@interface FontViewController (){
    NSArray* fontFamilies;
}

第 2 步:在您的接口文件 (.m) 上,在 viewDidLoad 上填充您的数组。

-(void)viewDidLoad{
    fontFamilies = [UIFont familyNames];
}

STEP3:最后,将这个添加到你的 cellForRowAtIndexPath 方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // The Magic :)    
    cell.textLabel.text = [fontFamilies objectAtIndex:indexPath.row];
    cell.textLabel.font = [UIFont fontWithName:[fontFamilies objectAtIndex:indexPath.row] size:12];

    return cell;
}

PS:确保已连接代理和数据源。情节提要(或 xib)上的 tableView Cell 属性应为“Cell”,并确保:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return fontFamilies.count;
}

有关表格视图的更多信息,请查看苹果文档here

或查看 appCoda 的 Table View 教程here

【讨论】:

  • 谢谢,虽然您看不到这样的字体。
  • 已编辑。很抱歉这篇文章很长,但这应该会告诉你每种字体的样子:) 干杯
猜你喜欢
  • 2013-09-02
  • 1970-01-01
  • 2011-07-23
  • 1970-01-01
  • 1970-01-01
  • 2011-09-10
  • 1970-01-01
  • 1970-01-01
  • 2011-08-04
相关资源
最近更新 更多