Add bottom border line to UI TextField view in SwiftUI / Swift / Objective-C / Xamarin
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
A bottom-only border is a common design pattern for text input fields because it looks lighter than the default rounded UITextField border. The exact implementation depends on the UI framework, but the basic idea is always the same: remove the standard border and draw a thin line at the bottom edge.
This article shows practical ways to do that in SwiftUI, UIKit with Swift, Objective-C, and Xamarin.iOS. The code is intentionally small so you can drop it into a real form without rebuilding the whole screen.
SwiftUI
SwiftUI does not expose a direct “bottom border only” style for TextField, so the usual approach is an overlay or background line.
This keeps the field declarative and easy to theme. You can swap the foregroundColor based on focus state or validation errors.
UIKit In Swift
In UIKit, the most common pattern is to remove the built-in border and add a sublayer.
Doing the layout work in viewDidLayoutSubviews ensures the line matches the final field size.
Objective-C
The Objective-C version uses the same CALayer idea.
If layout runs more than once, clear or reuse existing layers so you do not stack multiple borders on top of each other.
Xamarin.iOS
In Xamarin.iOS, the same technique applies through C# bindings.
As with UIKit, avoid adding duplicate sublayers every time the layout cycle runs.
Focus And Validation Styling
A static gray line is the simplest version, but bottom borders are often more useful when they respond to focus or error state. In SwiftUI, that might mean changing the line color with @FocusState. In UIKit or Xamarin, you can update the border layer color in editing callbacks such as editingDidBegin and editingDidEnd.
That small detail makes the border feel like part of the interaction model rather than a purely decorative line.
Common Pitfalls
- Forgetting to disable the default
UITextFieldborder style. - Adding a new bottom-border layer on every layout pass without removing the old one.
- Calculating the border frame before Auto Layout has finished.
- Styling only the line and forgetting focus or error feedback.
- Expecting SwiftUI
TextFieldto support a built-in bottom-border mode.
Summary
- In all frameworks, the pattern is to remove the default border and draw a line at the bottom edge.
- SwiftUI usually uses
overlaywith aRectangle. - UIKit, Objective-C, and Xamarin typically use a
CALayer. - Perform frame-based border layout after the field has its final size.
- Reuse or clear border layers so repeated layout passes do not create duplicates.

