Skip to content

SwiftUI: TextEditor

Last updated on June 24, 2020

Recently introduced in WWDC 2020, TextEditor is equivalent to UITextView in UIKit as it allows you to have the same functionality as UITextView with the text being selectable and editable.

Bear in mind that this only supports iOS 14 and above and can only be used in Xcode 12+.

A view that can display and edit long-form text.

Apple Documentation

Prerequisites

To follow along this tutorial, you’ll need some basic knowledge in:

  • A basic familiarity with Swift.
  • At least Xcode 12+
  • Only supports iOS 14+

TextEditor

It is encouraged that when using TextEditor that you intent to utilise it’s advantages of multiline. If you are only intending to use a single line, it is recommended to use TextField.

To begin, you will have to create a state where you could insert your text. Here I will be using a long line of text.

Then embed this within the VStack

The only problem I found when using this is that it doesn’t dismiss the keyboard when you are scrolling. Other than that, everything work pretty well.

Where to go From Here

Feel like SwiftUI is something that you will really like and want to explore more? Check out my page where you can learn how to use most of the components in SwiftUI.

Published inSwiftUI

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © DaddyCoding 2020.