为什么 UIButton.titleLabel?.text 在 Swift 5 (UIKit) 中更改后总是切换回来?
Why is UIButton.titleLabel?.text always switching back after I changed it in Swift 5 (UIKit)?
我 运行 我的 UIButton 有问题。
After the User presses the button, it activates an IBAction which is supposed to change the titleLabel.text
of my UIButton.
self.btnAppleHealthKit.titleLabel?.text = "Already pressed."
Whenever I press the button, the text changes for about a quarter second to "Already pressed"
, but switches back immediately to the previous text.
重要提示: 整个事情都在完成处理程序中,但我将其包装到 DispatchQueue.main.async { }
你们能想出为什么会出现这个错误吗?
提前感谢您的帮助。
看来,UIButton
不允许配置 titleLabel
的 text
或 color
。
Do not use the label object to set the text color or the shadow color.
Instead, use the setTitleColor(:for:) and setTitleShadowColor(:for:)
methods of this class to make those changes. To set the actual text of
the label, use setTitle(_:for:) (button.titleLabel.text does not let
you set the text).
我 运行 我的 UIButton 有问题。
After the User presses the button, it activates an IBAction which is supposed to change the
titleLabel.text
of my UIButton.
self.btnAppleHealthKit.titleLabel?.text = "Already pressed."
Whenever I press the button, the text changes for about a quarter second to
"Already pressed"
, but switches back immediately to the previous text.
重要提示: 整个事情都在完成处理程序中,但我将其包装到 DispatchQueue.main.async { }
你们能想出为什么会出现这个错误吗? 提前感谢您的帮助。
看来,UIButton
不允许配置 titleLabel
的 text
或 color
。
Do not use the label object to set the text color or the shadow color. Instead, use the setTitleColor(:for:) and setTitleShadowColor(:for:) methods of this class to make those changes. To set the actual text of the label, use setTitle(_:for:) (button.titleLabel.text does not let you set the text).