Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: UIButton empty in storyboard but has text while running

I'm developing a radio button module and I want an invisible button in a view.

I have deleted the text in the storyboard but when I run it, it shows "Button."

Here are some images:

Working version in the storyboard:

working version

Wrong version in runtime:

not working version

Here's what I've tried:

  • enabling the "ishidden" property
  • making it transparent
  • setting titleLabel.text to nothing (surprisingly the text comes back after clicking)

Setting the titleLabel.text = "" works until it is clicked where then the text returns.

like image 580
Adam A. Avatar asked Sep 06 '25 03:09

Adam A.


1 Answers

I faced this issue after I update my Xcode. Till then all buttons with empty title were showing fine. But after the update it started to show "Button" text for every empty buttons on device. At the same time in storyboard it was empty.

Writing button.setTitle("", for: .normal) everywhere was a difficult task since there were many buttons.

So after spending hours I discovered how to fix it.

  1. Go to storyboard
  2. Select the button
  3. Go to attribute inspector
  4. Select the style to default if it is something else (Mine was "Plain")
  5. now it might be showing title as "Button". Remove it.
  6. Thats it! now it won't show the text.

enter image description here

like image 58
Naval Hasan Avatar answered Sep 07 '25 16:09

Naval Hasan