-
-
Save qtxie/67b382155c516b6af7b61a985880380e to your computer and use it in GitHub Desktop.
List of monospace font
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIFontDescriptor on iOS 7 or later | |
NSDictionary *traitsAttributes = @{UIFontSymbolicTrait: @(UIFontDescriptorTraitMonoSpace)}; | |
NSDictionary *fontAttributes = @{UIFontDescriptorTraitsAttribute: traitsAttributes}; | |
UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:fontAttributes]; | |
NSArray *array = [fontDescriptor matchingFontDescriptorsWithMandatoryKeys:nil]; | |
for (UIFontDescriptor *descriptor in array) { | |
NSLog(@"%@", descriptor.postscriptName); | |
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorNameAttribute]); | |
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorVisibleNameAttribute]); | |
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorFamilyAttribute]); | |
// NSLog(@"%@", [descriptor objectForKey:UIFontDescriptorFaceAttribute]); | |
} | |
// NSLog(@"%@", array); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CTFontDescriptorRef on iOS and OS X | |
NSDictionary *traitsAttributes = @{(id)kCTFontSymbolicTrait: @(kCTFontMonoSpaceTrait)}; | |
NSDictionary *fontAttributes = @{(id)kCTFontTraitsAttribute: traitsAttributes}; | |
CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithAttributes((CFDictionaryRef)fontAttributes); | |
CFArrayRef array = CTFontDescriptorCreateMatchingFontDescriptors(fontDescriptor, NULL); | |
CFIndex count = CFArrayGetCount(array); | |
for (int i=0; i<count; i++) { | |
CTFontDescriptorRef descriptor =CFArrayGetValueAtIndex(array, i); | |
NSLog(@"%@", CFBridgingRelease(CTFontDescriptorCopyAttribute(descriptor, kCTFontNameAttribute))); | |
// NSLog(@"%@", CFBridgingRelease(CTFontDescriptorCopyAttribute(descriptor, kCTFontDisplayNameAttribute))); | |
// NSLog(@"%@", CFBridgingRelease(CTFontDescriptorCopyAttribute(descriptor, kCTFontFamilyNameAttribute))); | |
// NSLog(@"%@", CFBridgingRelease(CTFontDescriptorCopyAttribute(descriptor, kCTFontStyleNameAttribute))); | |
} | |
// CFShow(array); | |
CFRelease(fontDescriptor); | |
CFRelease(array); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NSFontDescriptor on OS X | |
NSDictionary *traitsAttributes = @{NSFontSymbolicTrait: @(NSFontMonoSpaceTrait)}; | |
NSDictionary *fontAttributes = @{NSFontTraitsAttribute: traitsAttributes}; | |
NSFontDescriptor *fontDescriptor = [NSFontDescriptor fontDescriptorWithFontAttributes:fontAttributes]; | |
NSArray *array = [fontDescriptor matchingFontDescriptorsWithMandatoryKeys:nil]; | |
for (NSFontDescriptor *descriptor in array) { | |
NSLog(@"%@", descriptor.postscriptName); | |
// NSLog(@"%@", [descriptor objectForKey:NSFontNameAttribute]); | |
// NSLog(@"%@", [descriptor objectForKey:NSFontVisibleNameAttribute]); | |
// NSLog(@"%@", [descriptor objectForKey:NSFontFamilyAttribute]); | |
// NSLog(@"%@", [descriptor objectForKey:NSFontFaceAttribute]); | |
} | |
// NSLog(@"%@", array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment