How to style UITextView to like Rounded Rect text field?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
UITextView does not have the built-in rounded-rect appearance that UITextField used to expose directly, but you can recreate that look with a few UIKit properties. The key pieces are border styling, corner radius, internal padding, and optional placeholder behavior so the control still feels like a polished form input.
Basic Rounded-Rect Styling
The visual shell mostly comes from the view’s layer.
This gives the text view a multiline text-field feel while keeping normal UITextView editing behavior.
Why Insets Matter
A rounded border without padding usually looks wrong because the text starts too close to the edge. textContainerInset is what makes the control feel comfortable rather than cramped.
That is one of the main visual differences between a quick hack and a production-ready control.
Adding a Focus State
Rounded text fields typically highlight when editing begins. You can mirror that behavior with UITextViewDelegate.
And in viewDidLoad:
This small change makes the control feel much closer to a native form field.
Placeholder Support
UITextView does not provide a placeholder property, so if you want the same experience users expect from a text field, add a label-based placeholder.
That gives you the form-field hint text that many users expect.
Dark Mode and Dynamic Type
Do not hard-code light-only colors if the app supports modern system themes. Prefer semantic colors such as:
- '
systemBackground' - '
secondarySystemBackground' - '
systemGray4' - '
placeholderText'
Also prefer preferredFont(forTextStyle:) so the text view works better with Dynamic Type.
Error Styling
If the text view participates in validation, keep error styling explicit and reusable.
That keeps the appearance consistent across screens instead of scattering ad hoc color changes through controllers.
Common Pitfalls
One common mistake is setting only cornerRadius and calling the job done. Without border color, width, and insets, the result usually does not feel like a rounded text field.
Another issue is implementing placeholder text but forgetting to hide it when the text is set programmatically.
A third pitfall is using fixed colors that look fine in light mode and unreadable in dark mode.
Summary
- Style
UITextViewwith layer border, corner radius, and text container insets. - Add a focus-state border change so editing feels like a form field.
- Use a placeholder label if you want text-field-like hint behavior.
- Prefer semantic UIKit colors and Dynamic Type-friendly fonts.
- Keep validation and styling helpers reusable across the app.
Related reading
- How to symbolicate crash log Xcode?
- How to take a screenshot programmatically on iOS
- How to tell at runtime whether an iOS app is running through a TestFlight Beta install
- How to tell if UIViewController's view is visible
- How to tell SwiftUI views to bind to nested ObservableObjects
- How to tell SwiftUI views to bind to nested ObservableObjects
- How to test equality of Swift enums with associated values
- How to test widget that is instantiated in didUpdateWidget in Flutter?
.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.