【发布时间】:2018-05-16 20:57:19
【问题描述】:
我有以下代码用于在我的按钮上设置图像:
button.setImage(UIImage(named: "X", in: getBundleForCommon(), compatibleWith: nil)?.withRenderingMode(.alwaysTemplate), for: .normal)
但是图像只有在被点击然后消失时才会出现在按钮上。
如何在我的按钮上持续显示点击时不受影响的图像。
【问题讨论】:
-
试试这行..Button.setBackgroundImage(pickedImage, for: .normal)
-
已经尝试过 setBackgroundImage。没有帮助。
-
您是否设置了除图像以外的按钮的任何属性?
-
@SharadChauhan,是的,也设置以下属性:Button.layer.cornerRadius = profilePicButton.frame.size.height / 2 Button.clipsToBounds = true Button.layer.borderWidth = 1.0 Button.layer.borderColor = VxColors.greyDark.color.cgColor -> 这些都生效了。只有在点击按钮时才能看到图像。