Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
December 16, 2017, 09:06:57 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
  Print  
Author Topic: List all fonts  (Read 4744 times)
edward.h
Newbie
*
Posts: 12


« on: December 30, 2012, 10:39:41 PM »

Prints list of all fonts to NSLog. Happy coding!

Code: (Objective-C)
    NSArray *availableFonts = [UIFont familyNames];
   
    availableFonts = [availableFonts sortedArrayUsingComparator:
            ^(id obj1, id obj2) {
                return [obj1 compare:obj2];
            }];
   
    int countedAvailableFonts = [availableFonts count];
   
    NSArray *availableFamily = [NSArray array];
    NSString *fontNameOutput = @"";
    NSString *fontFamilyName = @"";
   
    for (int i = 0; i < countedAvailableFonts; ++i) {
       
        fontFamilyName = [availableFonts objectAtIndex:i];
        availableFamily = [UIFont fontNamesForFamilyName:fontFamilyName];
       
        fontNameOutput = [fontNameOutput stringByAppendingString:@"\n\""];
        fontNameOutput = [fontNameOutput stringByAppendingString:fontFamilyName];
        fontNameOutput = [fontNameOutput stringByAppendingString:@"\"\n    "];
        fontNameOutput = [fontNameOutput stringByAppendingString:[availableFamily componentsJoinedByString:@"\n    "]];
       
    }
   
    NSLog(@"Available fonts: %@", fontNameOutput);

    // Output to a view on screen (not really useful, can't copy paste font names from there anyway, just for looks :))
    UITextView *tv = [[UITextView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    tv.text = fontNameOutput;
    [self.view addSubview:tv];
« Last Edit: December 30, 2012, 10:46:58 PM by edward.h » Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 classroomM.com. All rights reserved.