---
title: "TextFields with inputView"
slug: textfields-with-inputview
section: tech
date: 2015-07-15T12:43:00.000Z
canonical: https://roland.leth.ro/blog/tech/textfields-with-inputview
---

Let's say we have a `textField` with an `UIPickerView` as its `inputView`. 

The first problem is that we want the `textField` to not be editable, because we populate it with the value picked from the `picker`. This is the simple part:

```swift
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  return emailTextField == textField
}
```

The second problem is that the `textField` is still tappable, it still gets focus and the caret is still visible. 

We can't `return true` on `shouldBeginEditing`, we can't disable interactions, and `resigningFirstResponder` doesn't help either, since it closes the picker, and the whole idea is to use the picker natively, without creating a new set of methods that `showPicker` and `hidePicker`. 

Since a `textField`'s `tintColor` affects its caret too, the solution for our second problem turned out simple, after all:

```swift
emailTextField.tintColor = .clear
```

Bonus tip:

```swift
private var email = "" {
  didSet { 
    emailTextField.text = oldValue 
  }
}
```

This will automatically update the `textField` whenever `email` changes.