将字符串添加到uibutton标题

时间:2014-04-07 15:15:13

标签: ios objective-c nsstring uibutton

我正在尝试根据数组中的字符串更新按钮的标题,字符串nextplayername正常工作但是我正在努力获取显示后的文本。

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

基本上我希望按钮标题显示以下“nextplayername string”你的Up!

1 个答案:

答案 0 :(得分:1)

尝试:

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

使用格式规范从您想要的内容创建一个字符串。

或者,将字符串附加在一起:

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

更好,支持本地化:

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