Last active
November 12, 2015 13:39
-
-
Save pronebird/643e634ccc7ebc4c7904 to your computer and use it in GitHub Desktop.
preferredFontForTextStyle for each content size
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
//: Playground - noun: a place where people can play | |
/* | |
This playground prints CSV with all font sizes for each content size category and text style. | |
*/ | |
import UIKit | |
import XCPlayground | |
/* | |
Hack UIApplication's private preferredContentSizeCategory. | |
Force it to change content size so -preferredFontForTextStyle returns | |
the font with right descriptor | |
*/ | |
func changeContentSize(value: String) { | |
UIApplication.sharedApplication().setValue(value, forKey: "preferredContentSizeCategory") | |
} | |
let textStyles = [ | |
UIFontTextStyleHeadline, | |
UIFontTextStyleSubheadline, | |
UIFontTextStyleBody, | |
UIFontTextStyleFootnote, | |
UIFontTextStyleCaption1, | |
UIFontTextStyleCaption2, | |
UIFontTextStyleTitle1, | |
UIFontTextStyleTitle2, | |
UIFontTextStyleTitle3 | |
] | |
let categories = [ | |
// Standard | |
UIContentSizeCategoryExtraSmall, | |
UIContentSizeCategorySmall, | |
UIContentSizeCategoryMedium, | |
UIContentSizeCategoryLarge, | |
UIContentSizeCategoryExtraLarge, | |
UIContentSizeCategoryExtraExtraLarge, | |
UIContentSizeCategoryExtraExtraExtraLarge, | |
// Larger text sizes | |
UIContentSizeCategoryAccessibilityMedium, | |
UIContentSizeCategoryAccessibilityLarge, | |
UIContentSizeCategoryAccessibilityExtraLarge, | |
UIContentSizeCategoryAccessibilityExtraExtraLarge, | |
UIContentSizeCategoryAccessibilityExtraExtraExtraLarge | |
] | |
print("#,Content Size Category,Text Style,Font size") | |
var i = 1 | |
for category in categories { | |
changeContentSize(category) | |
for style in textStyles { | |
let font = UIFont.preferredFontForTextStyle(style) | |
print("\(i),\(category),\(style),\(font.pointSize)pt") | |
i++ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment