2015-09-07 59 views
0

選擇時,不能正確渲染這是它的外觀在故事板:的UIImageView在模擬器

enter image description here

...和選擇後:

enter image description here

這是我的子類:

@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) 
     } 
    } 
} 

在選擇時,這是在模擬輸出:

enter image description here

爲什麼ImageView的不渲染,因爲它應該?

回答

0

更改最後2行:

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