Add horizontal padding to TextEditor but prevent it from shifting scrollbar inside as a result

You added padding to external frame, but need to indent internal text container. The possible solution (as TextEditor is actually UITextView) to use appearance. So the solution would be to add the following in parent view of TextEditor

init() {
    UITextView.appearance().textContainerInset = 
         UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 12)   // << !!

// ... other code

    TextEditor(text: $text)
     .frame(maxWidth: .infinity, maxHeight: .infinity)

Tested with Xcode 12 / iOS 14

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top