8

I know how to limit the number of characters in a TextEditor. But is there a way to limit it by line number instead of by character?

With something like this?

TextEditor(text: $myText).lineLimit(3)
Just a coder
  • 15,480
  • 16
  • 85
  • 138
  • 1
    As of iOS 14 there is no simple solution (`TextEditor` is relatively new in SwiftUI, so let's hope it changes in the next version). You may try, however, to calculate everything manually - detecting the heights etc. – pawello2222 Jan 28 '21 at 00:07
  • Note that [the `TextEditor` docs](https://developer.apple.com/documentation/swiftui/texteditor) say, "If you want to change the spacing or font scaling aspects of the text, you can use modifiers like [lineLimit(_:)](https://developer.apple.com/documentation/swiftui/view/linelimit(_:))..." which implies that you can via `TextEditor(text: $someText).lineLimit(2)`. There doesn't appear to be any information clarifying if this has been added since iOS 14 or if it was added in a later release. – D M Feb 04 '22 at 22:56
  • Answered here https://stackoverflow.com/a/63165174/12299030 – Asperi May 15 '22 at 13:58
  • Does this answer your question? [How to get the TextEditor to display multiple lines?](https://stackoverflow.com/questions/63162118/how-to-get-the-texteditor-to-display-multiple-lines) – Ashley Mills Jan 16 '23 at 14:45

0 Answers0