Last active
March 8, 2016 00:42
-
-
Save donholly/8d42f88c901912773228 to your computer and use it in GitHub Desktop.
Find a minimum font size for a collection of strings (untested)
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
func minimumFontSizeForTitles(titles: [String], boundingSize: CGSize) -> CGFloat { | |
var minimumFontSize: CGFloat = 100 | |
let labelForSizing = UILabel(frame: CGRect(origin: CGPointZero, size: boundingSize)) | |
labelForSizing.font = UIFont.systemFontOfSize(minimumFontSize) | |
labelForSizing.adjustsFontSizeToFitWidth = true | |
for title in titles { | |
labelForSizing.text = title | |
minimumFontSize = min(minimumFontSize, labelForSizing.font.pointSize) | |
} | |
return minimumFontSize | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment