Chris Palmer Breuer Chris Palmer Breuer - 1 year ago 64
Swift Question

Programmatically image as UIButton but without attributes

At the moment the

looks like this:


The button images are colored icons generally and I am wondering how I can keep them that way without them changing the color.

The code I currently use simply sets the image for the

cell.iconImageButton.setImage(UIImage(named:, for: UIControlState.normal)

Any direction to the answer would be greatly appreciated! Thanks!

Answer Source

Use withRenderingMode with your UIImage object and set as alwaysOriginal.

cell.iconImageButton.setImage(UIImage(named:!.withRenderingMode(.alwaysOriginal), for: UIControlState.normal)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download