Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Create Button with two separate labels

Tags:

ios

uibutton

I would like create a button with two independent labels. I want to set in one button, two separate texts in different colors. e.g.

[myButton setTitle: @"Title" forState: UIControlStateNormal]; 
[myButton setTitle2: @"Title2" forState: UIControlStateNormal]; 

Is it even possible? Maybe I should need to create a new control? Can anyone help me? I will be very grateful for a tutorial step by step.

like image 548
MajsteR Avatar asked Dec 26 '22 08:12

MajsteR


1 Answers

If you wanted to do it all in Interface Builder you could place two UILabels where you want them in the view and then lay a UIButton over the top of them. Then with the Attributes Inspector change the UIButton's type to "Custom" and delete any existing label or placeholder text it has. This will make the button clear so both labels show through and you can set the UIButton's IBAction to do whatever you want to the two separate UILabels.

like image 160
drewdahl Avatar answered Jan 12 '23 21:01

drewdahl