Search code examples
xcodebuttontitleinvisible

XCode: Graphical button with invisible title


I have a bunch of buttons. They appears as an graphical image. If a user clicked on a button I can determine with

sender.titleLabel!.text!

which button the user pressed. But the title of the button appears in the view. I want only to show the image and give the button a invisible title. But I think that is not possible.

Me second solution is to create for each button an outlet. But I think with 30 buttons that is a very bad solution.


Solution

  • Option 1:

    For the button text color property set opacity to 0. The text is there, but fully transparent.

    Option 2:

    You may use the tag value to identify a button so you do not have to rely on the button title. You can set the tag value in interface builder (Xcode) or in code. (The tag is an integer.)

    I usually prefer option 2 as it is resilient to text changes over time (think of typos, translations for other languages etc.).