Why does a UICollectionViewCell with a UIButton have a monochrome / tinted image?

I create a UICollectionView and add one cell, which only subview is UIButton. This button has its own title and image. I checked that the image data is correct in the debugger.

When the button is drawn on the screen, I see the text and the image, however, the image looks as if it was filled with the color of the hue, obscuring the entire image other than its shape.

What am I missing here to show this as a regular button?

Update

It turns out that this does not apply to UICollectionView, but applies to all UIButtons in iOS7.

iOS 7 makes all the images in the buttons behave like template images using the image's alpha channel, along with the hue color, to create an image (similar to images on the tab bar). UIImage has a new renderMode property, which is considered β€œautomatic” by default, which allows the context to decide (template style for buttons)

This can be circumvented using the new imageWithRenderingMode : method in UIImage:

UIImage* myImage = [UIImage imageNamed:@"Foo.png"]; myImage = [myImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; [button setImage:myImage forState:UIControlStateNormal]; 
+8
ios objective-c ios7 uibutton uiimage
source share
2 answers

The easiest way to avoid this is to use a different UIButtonType . This is a UIButtonTypeSystem on iOS 7 that has this behavior, so you can use a custom button instead:

 UIButton *button = [UIButton buttonWithType: UIButtonTypeCustom]; [button setImage:myImage forState:UIControlStateNormal]; 
0
source share

When the background color of the UIButton lightText is that way, it will not cover the button image.

 UIButton.backgroundColor = UIColor.lightText 
0
source share

All Articles