UIButton: title doesn't show when setting background images for states

With the latest Xcode update (Xcode v7.1 beta 3), UIButton titles stopped showing up when you set different background images for the various control states. Is anyone else seeing this?


Here's some sample code of what worked in beta 2 and is no longer working in beta 3:


let button = UIButton(type: UIButtonType.System)
button.titleLabel?.font = UIFont.systemFontOfSize(36)!
button.setTitle(title, forState: UIControlState.Normal)
button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Focused)
button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Highlighted)
button.setBackgroundImage(UIImage(named: "read_normal_background.png"), forState: UIControlState.Normal)
button.setBackgroundImage(UIImage(named: "read_highlight_background.png"), forState: UIControlState.Focused)
button.layer.cornerRadius = 5


The images are just 10x10 pngs with the normal one being a gray and the highlight one being red.


When I comment out the lines where I'm setting the background image, the titles show up. My best guess is there's some ordering bug introduced in the latest release.

I experience the same but with button images instead of titles. I didn't have much time to look into it though. We should probably just file a radar.

I see the same thing.

After many tests, it seems that it is not the change of background that triggers this, but any change to the format of the titleLabel, like in your code:

button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)

I'm seeing this too. Even in Interface Builder, the background image seems to obscure the titleLabel.

Experiencing the same issue. The title shows up again when switching to another button, but the problem doesn't seem to resolve itself by calling

setNeedsDisplay()

or

setNeedsFocusUpdate()

on the button.

UIButton: title doesn't show when setting background images for states
 
 
Q