【问题标题】:Toggling the UILabel text on a UIButton programmatically以编程方式切换 UIButton 上的 UILabel 文本
【发布时间】:2011-11-06 04:16:03
【问题描述】:

我创建了以下插座

IBOutlet UIButton *oneButton;

以及按下按钮时的以下方法:

- (IBAction)digitPressed:(UIButton *)sender
{
    NSString *digit = sender.titleLabel.text;
    if ([digit isEqualToString:@"1"])
    {
        oneButton.titleLabel.text = @"11";
    } else if ([digit isEqualToString:@"11"])
    {
        oneButton.titleLabel.text = @"1";
    }
}

所以基本上我想在 1 和 11 之间切换按钮的标题,无论何时按下。通过放置断点,我看到程序通过了一行 oneButton.titleLabel.text = @"11";但标题从未真正改变。 oneButton 连接到 IB 中的文件所有者。

【问题讨论】:

    标签: iphone ios uibutton uilabel


    【解决方案1】:

    试试这样的方法:

    [oneButton setTitle:@"11" forState:UIControlStateNormal];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 2014-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多