2

I'm having some issues initializing an image in my code. I'm trying to change its tintColor property when the cell it sits in is highlighted like so:

iconImageView.tintColor = isHighlighted ? UIColor.white : UIColor.black

And to do so I'm initializing the image with the following line:

iconImageView.image = UIImage(named: imageName)?.renderingMode(.alwaysTemplate)

But I'm getting the following error:

Cannot call value of non-function type 'UIImage.RenderingMode'

Any suggestions?

1

2 Answers 2

1

The 'renderingMode' is a read-only property of UIImage.

Creates and returns a new image object with the specified rendering mode. You can use:

open func withRenderingMode(_ renderingMode: UIImage.RenderingMode) -> UIImage

Code snippet:

let imageView: UIImageView = UIImageView.init()
let image = UIImage.init(named: "name")?.withRenderingMode(.alwaysOriginal)
imageView.image = image
Sign up to request clarification or add additional context in comments.

Comments

1

renderingMode specifies the possible rendering modes for an image.

withRenderingMode(_:) creates and returns a new UIImage object with the specified rendering mode.

So, you need to use withRenderingMode(_:) which is a function versus renderingMode which is a property.

let image = UIImage(named: "imageName")?.withRenderingMode(.alwaysTemplate)
iconImageView.image.setImage(image, for: .normal)
iconImageView.image.tintColor = isHighlighted ? UIColor.white : UIColor.black

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.