Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton setText programmatically

I have about 10 UIButtons on xib file and want to setText programmatically

like image 387
user401383 Avatar asked Jul 28 '10 11:07

user401383


People also ask

How do I add text to UIButton?

Programmatically. To make a multi-line text in UIButton, you insert a new line character ( \n ) wherever you want in button title and set lineBreakMode to byWordWrapping . You can adjust text alignment with . textAlignment .

How do I change the text of a button in Swift?

You can omit UIControlState part and just write like button. setTitle("my text here", forState: . Normal) .


1 Answers

You might want to be more specific next time you ask a question.

You can try assign a different tag for each button in interface builder (or the same tag if thats what you need) and then use the following code

for (int i = 1 ; i<=10;i++) {      UIButton *myButton = (UIButton *)[myView viewWithTag:i];      [myButton setTitle:@"my text" forState:UIControlStateNormal]; } 
like image 98
Ron Srebro Avatar answered Oct 08 '22 12:10

Ron Srebro