Swift 在模拟器中选择时,UIButton中的UIImageView未正确渲染

Swift 在模拟器中选择时,UIButton中的UIImageView未正确渲染,swift,uiimageview,storyboard,Swift,Uiimageview,Storyboard,这是它在情节提要中的外观: 。。。选择后: 这是我的子类: @IBDesignable class WLButton: UIButton { override var selected: Bool { didSet { backgroundColor = selected ? UIColor.scooter() : UIColor.clearColor() imageView?.tintColor = select

这是它在情节提要中的外观:

。。。选择后:

这是我的子类:

@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没有按应有的方式呈现?

将最后两行更改为:

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