【问题标题】:UIButton Title Label Text Not Changing Using Storyboard or ProgrammaticallyUIButton 标题标签文本未使用情节提要或以编程方式更改
【发布时间】:2020-10-08 18:23:58
【问题描述】:

Xcode 12.0.1

我正在尝试使用情节提要删除 UIButton 上的标题标签文本。然后我计划以编程方式设置它。通过情节提要删除文本时,预览会显示已删除的文本。但是,当我构建和运行应用程序时,文本仍然存在。

以编程方式更改也不起作用。我尝试在控制器中更改 viewDidLoad()

            punchBtn.setTitle("Transfer", for: .normal)
            punchBtn.setTitle("Transfer", for: .application)
            punchBtn.setTitle("Transfer", for: .selected)
            punchBtn.setTitle("Transfer", for: .reserved)
            punchBtn.setTitle("Transfer", for: .highlighted)
            punchBtn.setTitle("Transfer", for: .disabled)
            punchBtn.setTitle("Transfer", for: .focused)

有趣的是,当按钮被选中时,文本会发生变化:

任何建议将不胜感激。

【问题讨论】:

  • 您应该对“punch”进行全文搜索。可能有一些重复的按钮,或者您在删除文本后没有按 Enter 键。
  • 试试我的答案,这对我有用

标签: ios xcode swift4 xcode-storyboard


【解决方案1】:

在文件 Main.strings 中,您会找到“punch”这个词。 从那里更改它,或者使用一个新按钮。

【讨论】:

    【解决方案2】:

    这听起来确实像是一个缓存问题,因为在应用程序中不再显示“Punch”。 Command-Shift-K 清理项目有望解决这个问题。

    如果这不起作用,则在整个工作区中搜索您使用“punch”一词的实例。

    【讨论】:

      【解决方案3】:

      试试这个!!!

      override func viewWillAppear(_ animated: Bool) {
          // other code
          // end of method
          // Change the text of your button
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-03-07
        • 2015-10-15
        • 2014-11-07
        • 2016-04-28
        • 2010-11-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多