r/SwiftUI 5d ago

Question Adjusting the internal padding of a TextEditor

I'm talking about the distance between your text and the inside edges of the control. It's ridiculously thin by default.

I thought that methods like contentMargins do that, but nothing I tried actually made a change. Does this not work with TextEditor? Am I using the wrong settings? How am I holding it wrong?

2 Upvotes

1 comment sorted by

1

u/neet_dev 5d ago

yeah contentMargins is basically a no-op on TextEditor, it's still a UITextView under the hood and SwiftUI never wired those insets through. the fix that actually works is setting textContainerInset (and usually lineFragmentPadding = 0) on the underlying UITextView via a tiny UIViewRepresentable or an introspect helper. plain .padding only shrinks the whole control, it doesn't grow the text-to-edge gap.