iOS檢視系統所有字型(帶效果圖)
阿新 • • 發佈:2018-12-10
NSString *sampStr = @"開發者ADreamClusive";
NSMutableAttributedString *fontStr = [NSMutableAttributedString new];
for(NSString * familyName in [UIFont familyNames]){
// NSLog(@"字型族科名 = %@",familyName); // 輸出字型族科名字
NSAttributedString *aAttrStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"字型族:%@\n", familyName] attributes:@{ NSFontAttributeName: [UIFont boldSystemFontOfSize:18], NSForegroundColorAttributeName: [UIColor redColor] }];
[fontStr appendAttributedString:aAttrStr];
for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName]){
// NSLog(@"\t%@",fontName); // 輸出字型族科下字樣名字
NSAttributedString *bAttrStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@:\t", fontName] attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:14] }];
[fontStr appendAttributedString:bAttrStr];
NSAttributedString *cAttrStr = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n", sampStr] attributes:@{ NSFontAttributeName: [UIFont fontWithName:fontName size:14] }];
[fontStr appendAttributedString:cAttrStr];
}
}
// textView為UITextView
self.textView.attributedText = fontStr;