我是通过 XCode 使用 SDK 版本 5.0 进行 iOS 开发的新手。在我的应用程序中,我需要在按下按钮时更改按钮的标题。
假设在正常状态下它是“unpushed”。我所需要的是,当我按下它时,按钮标签应更改为“按下”。
希望尽快得到帮助!
问候
这可能会对您有所帮助。
[btn setTitle:@"Pushed" forState:UIControlStateSelected];
[btn setTitle:@"UnPushed" forState:UIControlStateNormal];
-(IBAction)startSomething:(id)sender {
[sender setTitle:@"Hello" forState:UIControlStateNormal];
}
Or if you're wanting to toggle the name of the button, you can create a BOOL named "buttonToggled" (for example), and toggle the name this way:
-(IBAction)toggleButton:(id)sender {
if (!buttonToggled) {
[sender setTitle:@"Unpushed" forState:UIControlStateNormal];
buttonToggled = YES;
}
else {
[sender setTitle:@"pushed" forState:UIControlStateNormal];
buttonToggled = NO;
} }
在按钮操作中添加以下代码 - [Button setTitle:@"Pushed"];