我创建了一个自定义的UIButton
类。但是标题没有显示。我只得到背景颜色和圆角。但是标题不可见。
[另外,当我在iOS 13+模拟器中运行它时,其标题也显示为白色。但是,当我在iOS 12.4的设备中运行时,它无法正常工作。
这是我的代码:
public class CornerButton : UIButton {
public override init(frame: CGRect) {
super.init(frame: frame)
setup()
self.layoutIfNeeded()
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
self.layoutIfNeeded()
}
func setup() {
self.titleLabel?.font = UIFont(name: "Poppins-SemiBold", size: 12)
self.backgroundColor = UIColor(named: "BarColor")
self.setTitleColor(.white, for: .normal) // this line is not working
self.clipsToBounds = true
}
public override func layoutSubviews() {
self.roundCorners(corners: [.topRight,.bottomLeft], radius: 10)
}
}
您需要设置标题
self.setTitle("Some title", for: .normal)