iOS 设备上的字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8090916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:21:43  来源:igfitidea点击:

Fonts on iOS device

objective-cioscocoa-touchfonts

提问by cem

I've read the available font families by [UIFont familyNames], but I've got various lists on different devices (but with the same iOS version). Can somebody tell me, if the fonts listed with the method above, are including custom fonts provided by other installed applications or if those are only the fonts shipped with iOS?

我已经通过 阅读了可用的字体系列[UIFont familyNames],但我在不同的设备上有各种列表(但使用相同的 iOS 版本)。有人能告诉我,上面方法列出的字体是否包括其他已安装应用程序提供的自定义字体,或者这些只是iOS附带的字体?

回答by kakilangit

Yes, it shows all the fonts within your app, including the custom fonts you've added. Here's the shorter code to list all the fonts:

是的,它会显示您应用中的所有字体,包括您添加的自定义字体。这是列出所有字体的较短代码:

Objective-C

目标-C

for (NSString *familyName in [UIFont familyNames]){
    NSLog(@"Family name: %@", familyName);
    for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
        NSLog(@"--Font name: %@", fontName);
    }
}

Swift 2

斯威夫特 2

for familyName:AnyObject in UIFont.familyNames() {
    print("Family Name: \(familyName)")
    for fontName:AnyObject in UIFont.fontNamesForFamilyName(familyName as! String) {
        print("--Font Name: \(fontName)")
    }
}

Swift 3

斯威夫特 3

 for familyName:String in UIFont.familyNames {
     print("Family Name: \(familyName)")
     for fontName:String in UIFont.fontNames(forFamilyName: familyName) {
         print("--Font Name: \(fontName)")
     }
 }

回答by chrisallick

Here is the correct snippet for listing out all the fonts:

这是列出所有字体的正确片段:

    // 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]);
    }
}

回答by CutMaster

You'll find a list of all embedded fonts in iOS that don't need any extra class to build with, here : List Of Available iOS Fonts

您将在此处找到不需要任何额外类来构建的 iOS 中所有嵌入字体的列表:可用的 iOS 字体列表

回答by barfoon

Gruber posted a link to the fonts included a little while ago: iOS Fonts

Gruber 不久前发布了一个包含字体的链接:iOS 字体

Edit: The site he links to is iosfonts.com

编辑:他链接的网站是iosfonts.com

回答by Srikar Appalaraju

I believe those are only the fonts shipped with iOS. Any Custom fonts you need to find the respective .otfor .ttffiles & include that file in your project resource.

我相信这些只是 iOS 附带的字体。你需要的任何自定义字体,找到相应的.otf.ttf文件和在项目中包含的资源,文件。

Am saying this because, I wanted to use HelveticaNeue-UltraLightfont. Its listed in iOS & you see this font option in Xcode. But upon selecting nothing happens. For this to work I had to do the above & put in HelveticaNeue-UltraLightfont file.

之所以这么说是因为,我想使用HelveticaNeue-UltraLight字体。它在 iOS 中列出,您会在 Xcode 中看到此字体选项。但是在选择时什么也没有发生。为此,我必须执行上述操作并放入HelveticaNeue-UltraLight字体文件。

回答by Hemant Dixit

Please try this code :https://github.com/zynga/FontLabel/

请试试这个代码:https://github.com/zynga/FontLabel/

for checking Available iOS Fonts:

用于检查可用的 iOS 字体:

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];