Modify UIImage renderingMode from a storyboard/xib file

前端 未结 16 2361
别那么骄傲
别那么骄傲 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:17

    Another solution is to create a UIImageView subclass:

    final class TemplateImageView: UIImageView {
        override func awakeFromNib() {
            super.awakeFromNib()
            guard let oldImage = image else { return }
            image = nil
            image = oldImage.withRenderingMode(.alwaysTemplate)
        }
    }
    

    Then just set the class in the Interface Builder to TemplateImageView.

提交回复
热议问题