Fonts on iOS device

后端 未结 6 1224
醉酒成梦
醉酒成梦 2020-12-13 09:13

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 th

相关标签:
6条回答
  • 2020-12-13 09:31

    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

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

    Swift 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

     for familyName:String in UIFont.familyNames {
         print("Family Name: \(familyName)")
         for fontName:String in UIFont.fontNames(forFamilyName: familyName) {
             print("--Font Name: \(fontName)")
         }
     }
    
    0 讨论(0)
  • 2020-12-13 09:36

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

    for checking Available iOS Fonts:

    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]; 
    
    0 讨论(0)
  • 2020-12-13 09:43

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

    Edit: The site he links to is iosfonts.com

    0 讨论(0)
  • 2020-12-13 09:43

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

    Am saying this because, I wanted to use HelveticaNeue-UltraLight font. 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-UltraLight font file.

    0 讨论(0)
  • 2020-12-13 09:46

    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

    0 讨论(0)
  • 2020-12-13 09:47

    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]);
        }
    }
    
    0 讨论(0)
提交回复
热议问题