Ios 在TextEditor中添加水平填充,但防止滚动条向内移动

Ios 在TextEditor中添加水平填充,但防止滚动条向内移动,ios,swift,swiftui,text-editor,Ios,Swift,Swiftui,Text Editor,我正在使用一个文本编辑器,我想为它添加水平填充,这样文本就不会粘在任何一条边上。但是,问题是如果我包含它,并且其中的文本是可滚动的,那么滚动条就不会定位在最右边,而是被填充量移到了里面 TextEditor(text: $text) .background(Color.white) .foregroundColor(Color.black) .frame(maxWidth: .infinity, maxHeight: .inf

我正在使用一个文本编辑器,我想为它添加水平填充,这样文本就不会粘在任何一条边上。但是,问题是如果我包含它,并且其中的文本是可滚动的,那么滚动条就不会定位在最右边,而是被填充量移到了里面

        TextEditor(text: $text)
         .background(Color.white)
         .foregroundColor(Color.black)
         .frame(maxWidth: .infinity, maxHeight: .infinity)
         .customFont(.body)
         .lineSpacing(8)
         .padding(.leading)
         .padding(.trailing)

您在外部框架中添加了填充,但需要缩进内部文本容器。可能的解决方案(因为TextEditor实际上是UITextView)是使用外观。因此,解决方案是在
TextEditor

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

// ... other code

    TextEditor(text: $text)
     .background(Color.white)
     .foregroundColor(Color.black)
     .frame(maxWidth: .infinity, maxHeight: .infinity)
     .customFont(.body)
     .lineSpacing(8)
init(){
UITextView.appearance().TextContainerSet=
UIEdgeInSet(顶部:0,左侧:12,底部:0,右侧:12)//