I want to use the standard UIButton
but the text I want to put on the UIButton
has...
- ... multiple lines (each line is different string) and ...
- ... each line should have different font and size that ...
- ... automatically resizes font to fit the button width (not height to make it a bit easier)
So, even tough I would like to set the (preferred) font size for each line, I want the font-size to automatically size down so that each separate line fits nicely in the UIButton
(=same behaviour as the UILabel
AutoShrink / Minimum Font Scale).
What I don't want:
I do not want to start adding UILabels to the UIButton
(as subview for example) or using IB put UILabels on a scene and just draw an UIButton around it (why: I want the standard UIButton
highlighting behaviour)
What I want:
A clean solution using an attributed string, that given the width scales down the font (updates the attributed string I guess), line-by-line if required.
My idea, implement a function like this:
func addToAttributedString(attString : NSMutableAttributedString, plainString : String, font : UIFont, preferredSize : CGFloat, maxWidth : CGFloat)
And then I could make the attributed string by calling this with text 1,2,3... and insert a newline (\n) between them.
Any ideas?
sizeToFit()
will help you to adjust height as the text.Working with your code too :