Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton - How to set Minimum Font Size?

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?

like image 397
Alien Avatar asked Dec 10 '14 12:12

Alien


People also ask

How do I change the font size on a button in Swift?

button. titleLabel. adjustsFontSizeToFitWidth = YES; With this all labels adjust the text will size.

How do I change font size on labels in Swift?

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.

How do I change the button title color in Objective C?

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)


2 Answers

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

like image 44
Teetz Avatar answered Oct 05 '22 16:10

Teetz


button.titleLabel.numberOfLines = 1;
button.titleLabel.adjustsFontSizeToFitWidth = YES;
button.titleLabel.lineBreakMode = NSLineBreakByClipping;

copied from Set minimum font size UIButton with margin

like image 123
Anoop Vaidya Avatar answered Oct 05 '22 16:10

Anoop Vaidya