Reputation: 7351
I know with a UIButton, I can add additional UILabels as subviews:
[myButton addSubview: myLabel];
And (at least, with the default title label) I can set its text color when tapped by using:
[myButton setTitleColor:someColor forState:UIControlStateHighlighted]
My question is, how can I implement this functionality for additional UILabels added to the UIButton (if this is possible)?
Upvotes: 0
Views: 496
Reputation: 5664
Subclass UIButton and add your additional labels in there as instance variables. Then override -setHighlighted
and -setSelected
to adjust the additional labels as desired.
FYI - you call [myButton setTitleColor...]
, not [myButton.titleLabel setTitleColor...]
Upvotes: 2
Reputation:
You would have to set myLabel
s text color, before you added it as a subView.
Otherwise, you'll have to enumerate through the button's subviews and change each of your added label's text colors.
Update:
You can change the button title's font as follows:
myButton.titleLabel!.font = UIFont(name: "...", 10)
You can change the button's title color as follows:
colorsBtn.setTitleColor(UIColor.brownColor(), forState: UIControlState.Highlighted)
Upvotes: 1
Reputation: 7351
It seems my way of going about it isn't easy, but I realized I can just add an action to the UIButton
for the event UITouchDown
, and change the labels accordingly in the action.
Upvotes: 1