USO400


半分くらいうそです。

Tags


USO400

iOS10のFontFamilyName

23rd August 2017


旧OS

iOS10でフォント一覧を書き出すの忘れていた。

Swift3での取得方法が気に入らなかったので修正。ObjCとそーとのロジックが異なるけどもう不要かなって気もする。

取得方法

familyNameからfontNameを取得する。今回からソートするようにした。

////////////
// Objc
NSMutableArray<NSString*> *array = [NSMutableArray array];
for (NSString *familyName in [UIFont familyNames]) {
    for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
        [array addObject:fontName];
    }
}
[array sortUsingComparator:^NSComparisonResult(NSString * _Nonnull obj1, NSString * _Nonnull obj2) {
    return [obj1 compare:obj2 options:(NSCaseInsensitiveSearch)];
}];
[array enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    NSLog(@"%@", obj);
}];
////////////
// Swift 3
var fontNames = UIFont.familyNames.flatMap {
    return UIFont.fontNames(forFamilyName: $0)
}.sorted {
    $0.compare($1) == .orderedAscending
}
fontNames.forEach { (str) in
    print(str)
}

Swift 3 改良版はフォントのファミリーネームでソートしてからファミリーネーム単位でさらにフォント名でソートする、二重のソートにしているので必ずファミリーネームの順番で列挙される。

////////////
// Swift 3 改良版
UIFont.familyNames.sorted { $0.compare($1) == .orderedAscending }
    .flatMap { UIFont.fontNames(forFamilyName: $0).sorted { $0.compare($1) == .orderedAscending } }
    .forEach { (fontName) in
        print(fontName)
}

確認環境

iPhone Simulator (iOS10)

結果抜粋

AcademyEngravedLetPlain
AlNile
AlNile-Bold
AmericanTypewriter
AmericanTypewriter-Bold
AmericanTypewriter-Condensed
AmericanTypewriter-CondensedBold
AmericanTypewriter-CondensedLight
AmericanTypewriter-Light
AmericanTypewriter-Semibold
AppleColorEmoji
AppleSDGothicNeo-Bold
AppleSDGothicNeo-Light
AppleSDGothicNeo-Medium
AppleSDGothicNeo-Regular
AppleSDGothicNeo-SemiBold
AppleSDGothicNeo-Thin
AppleSDGothicNeo-UltraLight
Arial-BoldItalicMT
Arial-BoldMT
Arial-ItalicMT
ArialHebrew
ArialHebrew-Bold
ArialHebrew-Light
ArialMT
ArialRoundedMTBold
Avenir-Black
Avenir-BlackOblique
Avenir-Book
Avenir-BookOblique
Avenir-Heavy
Avenir-HeavyOblique
Avenir-Light
Avenir-LightOblique
Avenir-Medium
Avenir-MediumOblique
Avenir-Oblique
Avenir-Roman
AvenirNext-Bold
AvenirNext-BoldItalic
AvenirNext-DemiBold
AvenirNext-DemiBoldItalic
AvenirNext-Heavy
AvenirNext-HeavyItalic
AvenirNext-Italic
AvenirNext-Medium
AvenirNext-MediumItalic
AvenirNext-Regular
AvenirNext-UltraLight
AvenirNext-UltraLightItalic
AvenirNextCondensed-Bold
AvenirNextCondensed-BoldItalic
AvenirNextCondensed-DemiBold
AvenirNextCondensed-DemiBoldItalic
AvenirNextCondensed-Heavy
AvenirNextCondensed-HeavyItalic
AvenirNextCondensed-Italic
AvenirNextCondensed-Medium
AvenirNextCondensed-MediumItalic
AvenirNextCondensed-Regular
AvenirNextCondensed-UltraLight
AvenirNextCondensed-UltraLightItalic
Baskerville
Baskerville-Bold
Baskerville-BoldItalic
Baskerville-Italic
Baskerville-SemiBold
Baskerville-SemiBoldItalic
BodoniOrnamentsITCTT
BodoniSvtyTwoITCTT-Bold
BodoniSvtyTwoITCTT-Book
BodoniSvtyTwoITCTT-BookIta
BodoniSvtyTwoOSITCTT-Bold
BodoniSvtyTwoOSITCTT-Book
BodoniSvtyTwoOSITCTT-BookIt
BodoniSvtyTwoSCITCTT-Book
BradleyHandITCTT-Bold
ChalkboardSE-Bold
ChalkboardSE-Light
ChalkboardSE-Regular
Chalkduster
Cochin
Cochin-Bold
Cochin-BoldItalic
Cochin-Italic
Copperplate
Copperplate-Bold
Copperplate-Light
Courier
Courier-Bold
Courier-BoldOblique
Courier-Oblique
CourierNewPS-BoldItalicMT
CourierNewPS-BoldMT
CourierNewPS-ItalicMT
CourierNewPSMT
Damascus
DamascusBold
DamascusLight
DamascusMedium
DamascusSemiBold
DevanagariSangamMN
DevanagariSangamMN-Bold
Didot
Didot-Bold
Didot-Italic
DiwanMishafi
EuphemiaUCAS
EuphemiaUCAS-Bold
EuphemiaUCAS-Italic
Farah
Futura-Bold
Futura-CondensedExtraBold
Futura-CondensedMedium
Futura-Medium
Futura-MediumItalic
GeezaPro
GeezaPro-Bold
Georgia
Georgia-Bold
Georgia-BoldItalic
Georgia-Italic
GillSans
GillSans-Bold
GillSans-BoldItalic
GillSans-Italic
GillSans-Light
GillSans-LightItalic
GillSans-SemiBold
GillSans-SemiBoldItalic
GillSans-UltraBold
GujaratiSangamMN
GujaratiSangamMN-Bold
GurmukhiMN
GurmukhiMN-Bold
Helvetica
Helvetica-Bold
Helvetica-BoldOblique
Helvetica-Light
Helvetica-LightOblique
Helvetica-Oblique
HelveticaNeue
HelveticaNeue-Bold
HelveticaNeue-BoldItalic
HelveticaNeue-CondensedBlack
HelveticaNeue-CondensedBold
HelveticaNeue-Italic
HelveticaNeue-Light
HelveticaNeue-LightItalic
HelveticaNeue-Medium
HelveticaNeue-MediumItalic
HelveticaNeue-Thin
HelveticaNeue-ThinItalic
HelveticaNeue-UltraLight
HelveticaNeue-UltraLightItalic
HiraginoSans-W3
HiraginoSans-W6
HiraMinProN-W3
HiraMinProN-W6
HoeflerText-Black
HoeflerText-BlackItalic
HoeflerText-Italic
HoeflerText-Regular
Kailasa
Kailasa-Bold
KannadaSangamMN
KannadaSangamMN-Bold
KhmerSangamMN
KohinoorBangla-Light
KohinoorBangla-Regular
KohinoorBangla-Semibold
KohinoorDevanagari-Light
KohinoorDevanagari-Regular
KohinoorDevanagari-Semibold
KohinoorTelugu-Light
KohinoorTelugu-Medium
KohinoorTelugu-Regular
LaoSangamMN
MalayalamSangamMN
MalayalamSangamMN-Bold
MarkerFelt-Thin
MarkerFelt-Wide
Menlo-Bold
Menlo-BoldItalic
Menlo-Italic
Menlo-Regular
MyanmarSangamMN
MyanmarSangamMN-Bold
Noteworthy-Bold
Noteworthy-Light
Optima-Bold
Optima-BoldItalic
Optima-ExtraBlack
Optima-Italic
Optima-Regular
OriyaSangamMN
OriyaSangamMN-Bold
Palatino-Bold
Palatino-BoldItalic
Palatino-Italic
Palatino-Roman
Papyrus
Papyrus-Condensed
PartyLetPlain
PingFangHK-Light
PingFangHK-Medium
PingFangHK-Regular
PingFangHK-Semibold
PingFangHK-Thin
PingFangHK-Ultralight
PingFangSC-Light
PingFangSC-Medium
PingFangSC-Regular
PingFangSC-Semibold
PingFangSC-Thin
PingFangSC-Ultralight
PingFangTC-Light
PingFangTC-Medium
PingFangTC-Regular
PingFangTC-Semibold
PingFangTC-Thin
PingFangTC-Ultralight
SavoyeLetPlain
SinhalaSangamMN
SinhalaSangamMN-Bold
SnellRoundhand
SnellRoundhand-Black
SnellRoundhand-Bold
Symbol
TamilSangamMN
TamilSangamMN-Bold
Thonburi
Thonburi-Bold
Thonburi-Light
TimesNewRomanPS-BoldItalicMT
TimesNewRomanPS-BoldMT
TimesNewRomanPS-ItalicMT
TimesNewRomanPSMT
Trebuchet-BoldItalic
TrebuchetMS
TrebuchetMS-Bold
TrebuchetMS-Italic
Verdana
Verdana-Bold
Verdana-BoldItalic
Verdana-Italic
ZapfDingbatsITC
Zapfino

今回はキャプ無し。



2ストロークたまに4ストローク

View Comments