How to make a UILabel clickable?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
UILabel is designed for display, not interaction, so taps are ignored unless you opt in. When you want lightweight link-like behavior without the visual weight of a button, the usual solution is to enable interaction and attach a gesture recognizer.
Make The Label Receive Touches
The first requirement is easy to miss: a label does not accept touches until isUserInteractionEnabled is set to true. After that, you can attach a UITapGestureRecognizer and route the tap to a method on your view controller.
This approach works well when the whole label should behave like one tappable element.
There are only three moving parts in that example:
- The label is made interactive.
- A tap recognizer is attached to the label.
- The selector handles the event.
If your label is created in Interface Builder, the same idea applies. Connect the label as an outlet, set isUserInteractionEnabled = true in viewDidLoad, then add the recognizer there.
Make It Feel Like A Link
If the label is supposed to communicate navigation, style matters. Users have learned to associate blue text, underlining, and clear spacing with links. Accessibility also matters, because a plain label does not automatically announce itself as a button.
Here is a slightly stronger version that improves both presentation and accessibility:
The key addition is accessibilityTraits = [.button]. Without that, VoiceOver still treats the control as static text, which makes the interaction harder to discover.
When A UILabel Is The Wrong Tool
A tappable label is useful, but it is not always the best control. If the text should behave like a standard action, a UIButton is often better because it already supports touch states, accessibility, focus handling, and content insets.
Use a label when:
- You need inline text styling that looks like body copy.
- The interaction is simple and the whole label is tappable.
- You are matching an existing text-heavy layout.
Use a button when:
- The element is a primary action.
- You need pressed, highlighted, or disabled states.
- The control must behave consistently across accessibility and input modes.
That tradeoff matters because many bugs around clickable labels come from rebuilding behavior that UIKit already provides elsewhere.
Common Pitfalls
The most common mistake is forgetting isUserInteractionEnabled = true. If the recognizer is attached correctly but nothing happens, check that property first.
Another frequent issue is adding the recognizer before the label instance is actually on screen, then accidentally replacing the label later. If you create a new label and assign it to the same property, the recognizer remains attached to the old object.
Layout can also cause confusion. If constraints collapse the label to a tiny frame, the tap target becomes too small. Give link-like labels enough vertical padding or surrounding whitespace so they are usable on phones.
Accessibility is another weak point. A visually styled label may look clickable but still sound like plain text to assistive technologies. Setting button traits and testing with VoiceOver avoids that problem.
Finally, do not use multiple gesture recognizers unless you really need them. A single tap recognizer is enough for most cases, and stacking recognizers on labels can create conflicts that are harder to debug than the interaction itself.
Summary
- A
UILabelbecomes tappable only afterisUserInteractionEnabledis enabled. - '
UITapGestureRecognizeris the simplest way to trigger code from a label tap.' - Styling and accessibility should make the label behave like an intentional interactive control.
- For primary actions or richer states,
UIButtonis usually the better choice. - Most tap failures come from disabled interaction, tiny frames, or missing accessibility setup.
Related reading
- How to make a UILabel clickable?
- How to make an alert dialog fill 90 of screen size?
- How to make an Android device vibrate? with different frequency?
- How to make an Android device vibrate? with different frequency?
- How to make an Android Spinner with initial text Select One?
- How to make an HTTP request basic auth in Swift
- How to make an HTTP request basic auth in Swift
- How to make an ImageView with rounded corners?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.