如何为 SwiftUI 可滚动 TextField 设置 contentInset?

Tik*_*hev 5 textfield ios swift swiftui

我正在尝试使用 SwiftUI 重新创建 Telegram Messenger 消息 TextField。在电报应用程序中,TextField 有填充,当内容滚动时,内容会出现在该填充区域中:

\n

在此输入图像描述在此输入图像描述

\n

我正在尝试使用 SwiftUI 的 iOS 16 重新创建它TextField<S>(S,\xc2\xa0text:\xc2\xa0Binding<String>,\xc2\xa0prompt:\xc2\xa0Text?,\xc2\xa0axis:\xc2\xa0Axis),其中 axis.vertical带有.lineLimit(_ number: Int?)修饰符。

\n

但是当我应用填充和滚动时,内容内的边框出现:

\n

在此输入图像描述

\n

如何使用 swiftUI 实现 telegram 的应用程序 UI TextField

\n

我的源代码:

\n
if #available(iOS 16.0, *) {     \n    TextField(\n        "MainInputView.Message.TextView", text: $messageInputViewModel.message,                    \n        prompt: Text("MainInputView.Message.TextView", comment: "Message input placeholder"), axis: .vertical\n    )                 \n    .lineLimit(10)                 \n    .padding(.vertical, 8)\n    .padding(.horizontal, 15)\n    .background(Color.systemBackground)                \n    .clipShape(RoundedRectangle(cornerSize: .init(width: 20, height: 20)))\n}\n
Run Code Online (Sandbox Code Playgroud)\n