UITextField
iOS development
cursor customization
Swift programming
iOS UI design

Hide the cursor of a UITextField

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The insertion cursor in a UITextField is called the caret, and iOS normally shows it whenever the field becomes first responder. If you want the text field to stay editable but visually hide the caret, the most reliable solution is to subclass UITextField and override caretRect(for:) to return .zero.

Hide The Caret By Subclassing UITextField

This is the standard approach:

swift
1import UIKit
2
3final class CursorlessTextField: UITextField {
4    override func caretRect(for position: UITextPosition) -> CGRect {
5        return .zero
6    }
7}

Use it like any other text field:

swift
1let textField = CursorlessTextField(frame: CGRect(x: 20, y: 100, width: 240, height: 40))
2textField.borderStyle = .roundedRect
3textField.placeholder = "Type here"
4view.addSubview(textField)

The field still accepts input, but the blinking insertion caret is not drawn.

This is usually the cleanest answer when the goal is specifically "hide the cursor" without disabling editing.

A Simpler Visual Trick: Clear The Tint Color

Another common trick is setting the text field's tintColor to clear:

swift
textField.tintColor = .clear

This can hide the caret too, because the caret uses the control's tint color.

However, it is a broader visual change than overriding caretRect(for:). Depending on the situation, it may also affect selection handles or other tint-driven behavior. That is why subclassing is usually more explicit and controlled.

Decide Whether The Field Should Still Be Editable

Hiding the cursor is not the same as disabling editing.

Editable but cursorless:

swift
textField.isUserInteractionEnabled = true
textField.isEnabled = true

Non-editable display-only field:

swift
textField.isEnabled = false

If the field should only display text and never accept input, disabling interaction is simpler than hiding the caret. The cursor question matters mainly when the field still needs to receive typed input or programmatic focus.

If You Also Want To Suppress Selection

Sometimes designers want a field that accepts input from a custom keypad or scanner but should not show selection menus or editing handles either.

You can disable editing actions in a subclass:

swift
1import UIKit
2
3final class RestrictedTextField: UITextField {
4    override func caretRect(for position: UITextPosition) -> CGRect {
5        .zero
6    }
7
8    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
9        return false
10    }
11}

This is a stronger customization. Use it only when you really want to suppress normal text-editing affordances, because it changes expected platform behavior.

Common Use Cases

Hiding the cursor shows up in a few recurring designs:

  • custom PIN or OTP input UIs
  • scanner-driven input where typing is indirect
  • text fields that proxy input from another control
  • highly branded interfaces that replace the default editing appearance

These use cases can be valid, but they should still preserve clear user feedback in some other way.

For example, if the caret is hidden in a PIN entry control, users still need a visible indication of focus and input progress.

Accessibility And UX Considerations

A hidden cursor can make focus harder to understand, especially for users who expect normal iOS editing behavior. If you remove the caret, provide another signal such as:

  • a highlighted border
  • an active field background color
  • segmented input boxes
  • explicit instructional text

This matters because the caret is more than a decoration. It is part of how users understand where input will go.

So while the technical fix is simple, the design consequence is not trivial.

Common Pitfalls

The biggest mistake is hiding the caret when the real intent was simply to make the field non-editable. In that case, disabling the field or replacing it with a label is often clearer.

Another mistake is using tintColor = .clear without checking side effects on selection and editing UI. It may hide more than just the caret.

People also forget that hiding the cursor removes an important focus cue. If the field still accepts input, add another visible focus indicator.

Finally, if you use a subclass, make sure Interface Builder or code actually instantiates that subclass rather than a plain UITextField.

Summary

  • The most reliable way to hide a UITextField cursor is overriding caretRect(for:) and returning .zero.
  • Setting tintColor to clear can also hide the caret, but it is a broader visual change.
  • Hiding the cursor does not disable editing.
  • If you suppress the caret, provide another clear focus indicator for users.
  • Choose the simplest behavior that matches the real UX goal: editable without caret, or not editable at all.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.