Modify UIImage renderingMode from a storyboard/xib file

前端 未结 16 2359
别那么骄傲
别那么骄傲 2020-12-02 08:00

Is it possible to modify a UIImage\'s renderingMode from a storyboard or xib editor?

The goal is to apply tintColor to the par

16条回答
  •  我在风中等你
    2020-12-02 08:35

    Simple way to be set from Storyboard:

    @IBDesignable
    public class CustomImageView: UIImageView {
        @IBInspectable var alwaysTemplate: Bool = false {
            didSet {
                if alwaysTemplate {
                    self.image = self.image?.withRenderingMode(.alwaysTemplate)
                } else {
                    self.image = self.image?.withRenderingMode(.alwaysOriginal)
                }
    
            }
        }
    }
    

    Works fine on iOS 10 and Swift 3

提交回复
热议问题