UIButton标题标签文本不会使用情节提要或通过编程方式更改

问题描述

Xcode 12.0.1

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

original text

text removed

enter image description here

以编程方式更改也不起作用。我尝试更改控制器的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)

有趣的是文本被改变当选择按钮:

button selected

任何建议将不胜感激。

解决方法

在文件Main.strings中,您会找到这个单词“ punch”。 从那里更改它,否则采用新按钮。

,

这听起来像是缓存问题,因为应用程序中的任何地方都不再显示“ Punch”。 希望通过Command-Shift-K清理项目可以解决该问题。

如果这不起作用,则在整个工作空间中搜索使用“打孔”一词的实例。

,

尝试一下!

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