2

我是通过 XCode 使用 SDK 版本 5.0 进行 iOS 开发的新手。在我的应用程序中,我需要在按下按钮时更改按钮的标题。

假设在正常状态下它是“unpushed”。我所需要的是,当我按下它时,按钮标签应更改为“按下”。

希望尽快得到帮助!

问候

4

4 回答 4

1

这可能会对您有所帮助。

[btn setTitle:@"Pushed" forState:UIControlStateSelected];
[btn setTitle:@"UnPushed" forState:UIControlStateNormal];
于 2012-09-06T11:31:36.857 回答
0
     -(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;
    } }
于 2012-09-06T11:27:59.937 回答
0

在按钮操作中添加以下代码 - [Button setTitle:@"Pushed"];

于 2012-09-06T11:26:54.343 回答
0

请参阅控制状态

你可以这样做:

[button setTitle:@"pushed" forState:UIControlStateHighlighted];
于 2012-09-06T11:37:39.000 回答