小编Raj*_*j D的帖子

自定义 UIButton imageEdgeInsets/titleEdgeInsets 不起作用

和不适用于我的自定义imegEdgeInsets课程。我通过笔尖设置插图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) …
Run Code Online (Sandbox Code Playgroud)

uibutton ios swift

6
推荐指数
1
解决办法
2636
查看次数

标签 统计

ios ×1

swift ×1

uibutton ×1