[SOLVED] UIButton with custom image still shows titleLabel even though I set it to blank – Swift iOS

Issue

I’m pretty new to Swift, currently writing an AR game.
Seems like my issue is very basic, but I can’t figure it out.

I added a button to an AR Scene through the storyboard and linked it to an IBAction function (which works correctly when the button is clicked).
I gave the button an image and deleted the Title.
See how the button shows up in the storyboard:
button in Xcode storyboard without Title

But when I run the app, the button image shows up with a default label (saying "Button") as shown in this image:
button in iPhone screenshot WITH label next to the button image

I can’t figure out why this label is there and how to remove it.
Should I add the button programmatically instead of adding it through the storyboard?
Should the button be treated differently because it’s an AR app?

I was able to remove the label by adding the same UIButton as an IBOutlet and adding the following line in viewWillAppear:

restartButton.titleLabel?.text = ""

But this feels to me like a workaround and not a real solution.
Also, as soon as I click on the button, the label shows up again. I tried to add the same workaround line to the function when the button is clicked, but that didn’t help.

I’m sure I’m missing something very simple.
Your help would be appreciated.

Thanks!

Solution

When Interface Builder isn’t playing nice, I often open the Storyboard file in a text editor (I use Sublime Text) and edit it manually.

I had a similar issue – I had a button with an image, I had deleted the default "Button" title text in IB, which looked fine in Xcode, but when I ran it, the word "Button" was still there. So I found this line using Sublime Text and deleted it there:

<state key="normal" title="Button"/>

After that, it worked correctly.

Answered By – wildcat12

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.