【问题标题】:How to set the Button Image tint color?如何设置按钮图像色调颜色?
【发布时间】:2018-07-04 15:33:11
【问题描述】:

在 iOS 中单击时按钮图像图标的颜色会发生变化。
这是正在发生的事情的图像。

问题:颜色是默认,不是我设置的自定义颜色。
问题:如何为该按钮设置自定义 tint color?

【问题讨论】:

  • 显示您尝试过的代码?什么不工作?
  • 我已将图像提供给情节提要中的按钮。我的按钮类型是自定义的
  • 那么问题在哪里?
  • 设置 tint color 使图像变成单色,这是预期的行为。
  • 但我的色调是默认的

标签: ios xcode


【解决方案1】:

试试这个:

if let btnImg = yourBtnOutlet.imageView?.image {
       yourBtnOutlet.setImage(btnImg.withRenderingMode(.alwaysTemplate), for: .normal)
       yourBtnOutlet.tintColor = UIColor.red
 }

【讨论】:

    猜你喜欢
    • 2018-07-22
    • 2017-12-18
    • 1970-01-01
    • 2013-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    相关资源
    最近更新 更多