Reputation: 19880
I'm looking for an official list of available Fonts on iOS 4.2 since Apple included more fonts with the 4.2 update.
Unfortunately, I can't seem to find anything in the main documentation, nor on Apple's developer site; but I faintly remember that somewhere I saw an "official", that is, a list made by Apple of all fonts available on iOS.
If someone could point me to a piece of documentation, that would be nice. :)
Thanks in advance!
Found an app called "Fonts" on the App Store (free). It simply displays all fonts on the device.
Upvotes: 5
Views: 6697
Reputation: 357
You can check the available font for your device (iPhone or iPad) using this method
- (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);
}
}
Copy/paste this on a class and use [self getAllFonts];
The list should be displayed on your logs
STEP1: Add this to your header
@interface FontViewController (){
NSArray* fontFamilies;
}
STEP2: On your interface file (.m), populate your array on viewDidLoad.
-(void)viewDidLoad{
fontFamilies = [UIFont familyNames];
}
STEP3: Finally, add this to you cellForRowAtIndexPath method
- (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: Make sure you got the delegate and datasource connected. Your tableView Cell property on your storyboard (or xib) should be "Cell", And make sure that:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return fontFamilies.count;
}
For more info on table views, check the apple documentation here
or see appCoda's Table View tutorial here
Upvotes: 2