Chris Palmer Breuer Chris Palmer Breuer - 17 days ago 5
Swift Question

Programmatically image as UIButton but without attributes

At the moment the

CollectionViewController
looks like this:

cvc

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
UIButton
.

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


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

Answer

Use withRenderingMode with your UIImage object and set as alwaysOriginal.

cell.iconImageButton.setImage(UIImage(named: discover.name)!.withRenderingMode(.alwaysOriginal), for: UIControlState.normal)