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
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.
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.
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];
}
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