UIButton image disappears when “debug executable” is unchecked in edit scheme

I have created a UIButton in storyboard, and have set an image for the UIButton (the image is in assets.xcassets). The button shows up in the simulator and when run on an iPhone. However, if I quit the app on the iPhone and open it again, the button disappears, but I am still able to click it and it works. The same thing happens when I uncheck "debug executable." When I check the view hierarchy, the button is on top of the hierarchy but is invisible. Using infoButton.isHidden = false also does not work. In my button's view controller, I have called view.bringSubviewToFront(_: infoButton) in viewDidLoad().

I have also tried setting the button's image programmatically, but it still doesn't show up. However, when I set a background color for the button with infoButton.backgroundColor = UIColor.blue, I can see a blue box where the button should be, but no image. Here are my settings for the UIButton:

I would appreciate any help, thank you.

Post not yet marked as solved Up vote post of rainypuns Down vote post of rainypuns
1.3k views

Replies

I note that the button image is info but shows info.circle. You should check.

Try also a system button, instead of custom.

  • I'm actually using my own image for the button, which happens to be called "info." I've tried changing the button image to a system image, and then changing the button type to system, but the button still disappears. This button's problem seems to be when debug executable is unchecked, since otherwise it shows up fine.

Add a Comment

Hello. Did you find solution for this problem? I also have absolutely same one and can't resolve it.

  • I found solution. The code below working correctly on iOS 13, but now there is some bug. Just need to remove extension of UIButton:

    extension UIButton { open override func layoutSubviews() { super.layoutSubviews() } }

Add a Comment