【问题标题】:UIImageView in UIButton is not rendered properly when selected in Simulator在模拟器中选择时,UIButton 中的 UIImageView 未正确呈现
【发布时间】:2015-12-02 19:30:06
【问题描述】:

这是它在故事板中的样子:

...选择后:

这是我的子类:

@IBDesignable class WLButton: UIButton {

    override var selected: Bool {

        didSet {

            backgroundColor = selected ? UIColor.scooter() : UIColor.clearColor()
            imageView?.tintColor = selected ? UIColor.whiteColor() : UIColor.grayColor()
            imageView?.image = imageView?.image?.imageWithRenderingMode(.AlwaysTemplate)
        }
    }
}

选择时会在模拟器中输出:

为什么 imageView 没有按应有的方式呈现?

【问题讨论】:

    标签: swift uiimageview storyboard


    【解决方案1】:

    将最后两行改为:

    setImage(imageView?.image?.imageWithRenderingMode(.AlwaysTemplate), forState: UIControlState.Selected)
    tintColor = UIColor.whiteColor()
    

    【讨论】:

      猜你喜欢
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 2022-07-16
      • 2021-07-07
      相关资源
      最近更新 更多