We all know how to create dynamic UILabel font(Single Line) -
lbl.adjustsFontSizeToFitWidth = true
lbl.numberOfLines = 1
lbl.minimumScaleFactor = 0.1
lbl.baselineAdjustment = UIBaselineAdjustment.AlignCenters
lbl.textAlignment = NSTextAlignment.Center
The problem is that it gives different results for each given string. So for example if i have a string "Hello"
and "Hello World"
the calculated font size will be different.I need to create dynamic font with a single size for all strings.
Example from my project :
Example from iPhone 6 built in camera effects(As you can see all the UILabels font sizes matches) :
What i was thinking to do?
Basically I know what is the largest string i'll have. So i was thinking somehow calculate(in a effective way) what would be the font size for the largest string in the given CGSIze. So it will always stay in bounds. Any suggestions?
See Question&Answers more detail:os