Reputation: 145
i'm new on ios and i wonder if is it possible to change button's title font when it is pressed, i can change button's color when its highlighted as:
[button setTitleColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0] forState:UIControlStateHighlighted];
is there anything like this to change button's font size, without writing button pressed methods.(i want to change font on highlighted state, so i'm not sure if buttonPressed method will work clearly)
Upvotes: 2
Views: 5002
Reputation: 910
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom];
[myButton setTitle:@"Click Button" forState:UIControlStateNormal];
myButton.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[myButton.titleLabel setFont:[UIFont systemFontOfSize:10]];
[self.view addSubview:myButton];
Upvotes: 1
Reputation: 7260
You can use the titleLabel
property:
button.titleLabel.font = [UIFont systemFontOfSize: 12];
EDIT: You'll have to use it in the actions UIControlEventTouchDown
, UIControlEventTouchUpInside
and UIControlEventTouchUpOutside
.
Upvotes: 5
Reputation: 689
If you are insistent upon not writing a button pressed method, you could try your luck with attributed strings. UIButton has the method
– setAttributedTitle:forState:
You can change the highlighted state to use a version of your string with the correct font that way.
You can learn more about attributed strings in the Apple Documentation.
Yet another solution is to use custom images for your buttons. And use the method
– setImage:forState:
Upvotes: 2