Skip to content

Instantly share code, notes, and snippets.

@shaps80
Last active May 6, 2023 22:17
Show Gist options
  • 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.
@vanities
Copy link

this amazing- thanks for sharing

@shaps80
Copy link
Author

shaps80 commented Feb 22, 2021

this amazing- thanks for sharing

Now worries, thanks!

@X901
Copy link

X901 commented Mar 18, 2021

there is error , in these code

var placeholderView: some View { Group { if isEmpty { Text(title) .foregroundColor(.secondary) .multilineTextAlignment(placeholderAlignment) .font(placeholderFont) } } }

Return type of property 'placeholderView' requires that 'Group' conform to 'View'

@shaps80
Copy link
Author

shaps80 commented Mar 18, 2021

@X901 actually that should be using a view builder anyway, updated, thanks!

@X901
Copy link

X901 commented Mar 21, 2021

@X901 actually that should be using a view builder anyway, updated, thanks!
Thank you

@vikdenic
Copy link

This is an excellent UITextView wrapper 🙌 Thank you

@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