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?
问题:
回答1:
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)")
}
}
回答2:
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]);
}
}
回答3:
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
回答4:
Gruber posted a link to the fonts included a little while ago: iOS Fonts
Edit: The site he links to is iosfonts.com
回答5:
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.
回答6:
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];