user3502233
user3502233

Reputation: 25

Add a string to a uibutton title

I am trying to update the title of a button based on an string from an array the string nextplayername is working fine however im strugling to get the text after it to display.

 [self.shownextbutton setTitle:nextplayerName @"Your Up! " forState:UIControlStateNormal];

Basically i want the button title to display the following "nextplayername string" Your Up!

Upvotes: 0

Views: 426

Answers (1)

Wain
Wain

Reputation: 119031

Try:

... setTitle:[NSString stringWithFormat:@"%@ You're Up!", nextplayerName] ...

to create a string from your desired content using a format specification.

Alternatively, append the strings together:

NSString *title = [nextplayerName stringByAppendingString:@" You're Up!"];
... setTitle:title ...

Better, support localisation:

... setTitle:[NSString stringWithFormat:NSLocalizedString(@"%@ You're Up!", @"Batter up!"), nextplayerName] ...

Upvotes: 1

Related Questions