Skip to content

Instantly share code, notes, and snippets.

@shaps80
Last active May 6, 2023 22:17
Show Gist options
  • Select an option

  • Save shaps80/8a3170160f80cfdc6e8179fa0f5e1621 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

this amazing- thanks for sharing

@shaps80

shaps80 commented Feb 22, 2021

Copy link
Copy Markdown
Author

this amazing- thanks for sharing

Now worries, thanks!

@X901

X901 commented Mar 18, 2021

Copy link
Copy Markdown

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

shaps80 commented Mar 18, 2021

Copy link
Copy Markdown
Author

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

@X901

X901 commented Mar 21, 2021

Copy link
Copy Markdown

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

@vikdenic

Copy link
Copy Markdown

This is an excellent UITextView wrapper 🙌 Thank you

@shaps80

shaps80 commented Apr 21, 2021

Copy link
Copy Markdown
Author

@vikdenic thanks! Glad you found it useful 👍

@jhowlin

jhowlin commented May 8, 2021

Copy link
Copy Markdown

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

shaps80 commented May 8, 2021

Copy link
Copy Markdown
Author

You’re welcome. Glad you found it useful!

@shaps80

shaps80 commented Sep 7, 2021

Copy link
Copy Markdown
Author

@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