Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Size of Text on a UIButton

Client wants me to do something, i have just checked and i m quite sure its not possible. He asked to put a text on a Button ( UIButton ). (Default State Configuration) And when the user clicks it the text should enlarge. (Highligted State Configuration) I have checked by selecting Highligted State Configuration and then changed the size of text in the Interface Builder but i didnt work . The text changed for Default State Configuration as well. Please tell me if there is any way to do it.

Thanks!

Taimur

like image 763
Taimur Ajmal Avatar asked May 27 '10 15:05

Taimur Ajmal


People also ask

How do I change font size in UIButton?

To set a different font on UIButton programmatically you will need to create a new instance of UIFont object. The initializer of UIFont accepts two arguments: name and size. where the “GillSans-Italic” is a font name you want to set.

How do you change the font on UILabel?

To change the font or the size of a UILabel in a Storyboard or . XIB 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.


1 Answers

You might not be able to do it in IB, but you can certainly do it with a pair of actions. I'm assuming that the highlighted state will only be active while the button is pressed. You can modify this code if that's not the case (to toggle the state back to normal when the highlighted state ends).

- (IBAction)buttonDown:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.titleLabel.font = [UIFont boldSystemFontOfSize:18.0];
}

- (IBAction)buttonUp:(id)sender {
    UIButton *button = (UIButton *)sender;
    button.titleLabel.font = [UIFont boldSystemFontOfSize:15.0];
}
like image 105
warrenm Avatar answered Oct 13 '22 05:10

warrenm