ios14 - 按钮标题和图像未显示
ios14 - Button Title and Image Not getting Displayed
按钮标题和图像未呈现。在 iOS13 及以下工作正常,但在更新到 Xcode12.0.1 和 iOS14 后,它不工作了。
let viewAllButton: RoundedButton = {
let button = RoundedButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.backgroundColor = .red
button.setTitle("View all", for: .normal)
button.setTitleColor(.white, for: .normal)
return button
}()
class RoundedButton: UIButton {
override func draw(_ rect: CGRect) {
super.draw(rect)
self.layer.cornerRadius = self.bounds.height / 2
self.layer.masksToBounds = true
}
}
尝试先设置标题颜色再设置setTitle。 (我也遇到过类似的问题)。
Xcode12.0.1,iOS14,Swift5.3
实际上问题出在我的代码库中的冗余代码中。
extension UIButton {
open override func layoutSubviews() {
super.layoutSubviews()
}
}
我刚把这个放在我的扩展程序中。这不会在 iOS 13 及以下版本中引起任何问题。
重现步骤:
- 在您的项目中添加以上代码。
- 运行 项目(发布或调试模式)模拟器中的项目(按钮正确呈现)并终止应用程序。
- 现在,单击应用程序图标启动应用程序,您将看到按钮内容消失。
奇怪的错误,我希望它能节省一些人的时间。
按钮标题和图像未呈现。在 iOS13 及以下工作正常,但在更新到 Xcode12.0.1 和 iOS14 后,它不工作了。
let viewAllButton: RoundedButton = {
let button = RoundedButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.backgroundColor = .red
button.setTitle("View all", for: .normal)
button.setTitleColor(.white, for: .normal)
return button
}()
class RoundedButton: UIButton {
override func draw(_ rect: CGRect) {
super.draw(rect)
self.layer.cornerRadius = self.bounds.height / 2
self.layer.masksToBounds = true
}
}
尝试先设置标题颜色再设置setTitle。 (我也遇到过类似的问题)。
Xcode12.0.1,iOS14,Swift5.3
实际上问题出在我的代码库中的冗余代码中。
extension UIButton {
open override func layoutSubviews() {
super.layoutSubviews()
}
}
我刚把这个放在我的扩展程序中。这不会在 iOS 13 及以下版本中引起任何问题。
重现步骤:
- 在您的项目中添加以上代码。
- 运行 项目(发布或调试模式)模拟器中的项目(按钮正确呈现)并终止应用程序。
- 现在,单击应用程序图标启动应用程序,您将看到按钮内容消失。
奇怪的错误,我希望它能节省一些人的时间。