My question is simple. Is there any way to set a minimum font size for UIButton
like this can be easily set up with UILabel
?
button. titleLabel. adjustsFontSizeToFitWidth = YES; With this all labels adjust the text will size.
Change Font And Size Of UILabel In StoryboardXIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.
You can use your custom color by using RGB method:button. setTitleColor(UIColor(displayP3Red: 0.0/255.0, green: 180.0/255.0, blue: 2.0/255.0, alpha: 1.0), for: . normal)
Anoop's answer works like a charm. You can also do this in IB using User Defined Runtime Attributes:
- choose Button in IB
- Add Attribute
- KeyPath: titleLabel.adjustsFontSizeToFitWidth
- Type: Boolean
- Value: true
Screenshot from IB
button.titleLabel.numberOfLines = 1;
button.titleLabel.adjustsFontSizeToFitWidth = YES;
button.titleLabel.lineBreakMode = NSLineBreakByClipping;
copied from Set minimum font size UIButton with margin
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With