ios - UIButton.setTitle 没有将 UIButton.titleLabel.text 设置为空字符串
问题描述
这不是问题,但我发现UIButton.setTitle
没有设置UIButton.titleLabel.text
为""
. 所以如果你想设置UIButton.titleLabel.text
你""
应该使用UIButton.titleLabel.text = ""
after UIButton.setTitle("", for: .normal)
。
在操场上它看起来像:
import UIKit
let button = UIButton()
button.setTitle("1", for: .normal)
print(button.titleLabel?.text ?? "no value")
//print 1
button.setTitle("2", for: .normal)
print(button.titleLabel?.text ?? "no value")
//print 2
button.setTitle("3", for: .normal)
print(button.titleLabel?.text ?? "no value")
//print 3
button.setTitle("", for: .normal)
print(button.titleLabel?.text ?? "no value")
//print 3 not ""
button.titleLabel?.text = ""
print(button.titleLabel?.text ?? "no value")
//print ""
但当然button.titleLabel?.text = ""
只有在button.setTitle("", for: .normal)
button.setTitle("3", for: .normal)
button.titleLabel?.text = ""
print(button.titleLabel?.text ?? "no value")
//print 3
我不明白为什么会这样。也许有人可以解释为什么?
解决方案
推荐阅读
- tasmota - 无论如何让tasmota模仿按钮点击?
- c# - 在结构中编组 C++ win32 类型以在 C# 中的函数中使用
- python - PyTube:PrivateVideo 异常不起作用
- c - 使用 while(str[n++]!='\0') 计算字符串的长度
- ruby - Ionic Appflow - 找不到“Bundler”
- scala - Scala 致命警告但不包括弃用标志不起作用
- python - Django Form 从另一个没有外键的模型中选择
- python-3.x - 在线下载时Mac可执行文件不起作用
- performance - 这是正确的时间复杂度吗?
- html - SVG 渲染问题 - Firefox 切断了兄弟 SVG 元素 - 有解决方法吗?