Add placeholder text inside UITextView in Swift?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
UITextView does not provide a built-in placeholder property like UITextField, so you have to implement the behavior yourself. The most reliable approach is to add a label inside the text view, keep its styling aligned with the text view’s font and insets, and hide or show it when the text changes.
Why A Label Is The Best Approach
Some quick solutions fake a placeholder by setting the text view’s text property to a light-gray string and clearing it when editing begins. That works at first, but it complicates real text handling because the placeholder becomes mixed with actual content.
A separate UILabel avoids that problem entirely:
- the placeholder is presentation only
- the real
textremains real user input only - styling and layout stay easier to control
A Reusable UITextView Subclass
A subclass gives you one component you can reuse anywhere.
This keeps the placeholder behavior independent of the stored text value.
Using The Subclass
Once the subclass exists, usage is simple.
If you create it in Interface Builder, the subclass still works because the initializer and notification setup are handled in both code paths.
Why layoutSubviews Matters
The placeholder position must respect the text view’s content insets and width. If you set the label frame only once during initialization, it can be wrong after Auto Layout resizes the text view.
Using layoutSubviews ensures the placeholder moves correctly when:
- the device rotates
- dynamic type changes font size
- the text view frame changes through constraints
Styling Considerations
To make the placeholder feel native:
- match the text view font
- use
.placeholderTextor a light gray color - respect
textContainerInset - update layout when fonts or bounds change
Those details matter more than the basic hide-show logic.
Common Pitfalls
The most common mistake is storing the placeholder string directly in text. That makes placeholder state indistinguishable from user input and complicates validation, saving, and accessibility.
Another mistake is forgetting to update the placeholder layout after Auto Layout changes the text view size.
A third issue is not removing the notification observer in custom reusable components, which can create lifecycle bugs in older observer patterns.
Summary
- '
UITextViewhas no built-in placeholder support.' - A child
UILabelis the cleanest implementation strategy. - Keep the placeholder separate from the real
textvalue. - Update placeholder visibility on text changes and layout on size changes.
- A small reusable subclass gives the most maintainable solution.

