Skip to content

Instantly share code, notes, and snippets.

@shaps80
Last active May 6, 2023 22:17
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save shaps80/8a3170160f80cfdc6e8179fa0f5e1621 to your computer and use it in GitHub Desktop.
Save shaps80/8a3170160f80cfdc6e8179fa0f5e1621 to your computer and use it in GitHub Desktop.
A SwiftUI view that wraps a UITextView but provides almost all functionality though modifiers and attempts to closely match the Text/TextField components.
@shaps80
Copy link
Author

shaps80 commented Apr 21, 2021

@vikdenic thanks! Glad you found it useful 👍

@jhowlin
Copy link

jhowlin commented May 8, 2021

REALLY GREAT!

I've attempted this myself and had the hardest time with the sizing. It would always run off the edges, and the height wouldn't be respected by the parent view. (My primary use case for this type of multi-line editing is in a Form, where scrolling is disabled and the "cell" should self-size. )

It appears the key to solving my horizontal sizing issue is setting the contentCompressionResistance being "low," (which I don't understand). The solution to the vertical issue is then solvable as you've done (although I don't really get why the frame(minheight:maxHeight) works...)

Anyway, huge thanks!

@shaps80
Copy link
Author

shaps80 commented May 8, 2021

You’re welcome. Glad you found it useful!

@shaps80
Copy link
Author

shaps80 commented Sep 7, 2021

@jhowlin @vikdenic @X901 @vanities

Just to let you know I'm now officially supporting this (and many other) SwiftUI views via a dedicated organisation, SwiftUI+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment