和不適用于我的自定義imegEdgeInsets課程。我正在通過 nib 設定插圖titleEdgeInsetsUIButton

.
自定義UIButton類代碼
class FilledButton: kButton {
private var bgColor = AppTonalPalette.color(.primary)
private var bgColorPressed = AppTonalPalette.color(.primary).withAlphaComponent(0.88)
private var foregroundColor = AppTonalPalette.color(.onPrimary)
private var bgColorDisabled = UIColor.init("#1F1F1F", alpha: 0.12)
private var foregroundColorDisabled = AppTonalPalette.color(.onSurface)
override func layoutSubviews() {
super.layoutSubviews()
updateViews()
}
func updateViews() {
tintColor = isEnabled ? foregroundColor : foregroundColorDisabled
setTitleColor(isEnabled ? foregroundColor : foregroundColorDisabled, for: .normal)
setTitleColor(isEnabled ? foregroundColor : foregroundColorDisabled, for: .highlighted)
backgroundColor = isEnabled ? (isHighlighted ? bgColorPressed : bgColor) : bgColorDisabled
}
}
class kButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
}
override func draw(_ rect: CGRect) {
super.draw(rect)
setup()
}
func setup() {
titleLabel?.font = AppFont.fontOf(size: 14, style: .Regular)
setNeedsLayout()
}
}
我還嘗試在 mu 自定義類代碼中添加插圖,例如:
func updateViews() {
tintColor = isEnabled ? foregroundColor : foregroundColorDisabled
setTitleColor(isEnabled ? foregroundColor : foregroundColorDisabled, for: .normal)
setTitleColor(isEnabled ? foregroundColor : foregroundColorDisabled, for: .highlighted)
backgroundColor = isEnabled ? (isHighlighted ? bgColorPressed : bgColor) : bgColorDisabled
if imageView?.image != nil {
imageEdgeInsets = .init(top: 0, left: 0, bottom: 0, right: 10)
titleEdgeInsets = .init(top: 0, left: 10, bottom: 0, right: 0)
}
}
但還是一樣。這里缺少什么?
uj5u.com熱心網友回復:
嘗試通過按鈕屬性檢查器將按鈕樣式更改為默認樣式。

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/425586.html
