Swiftui Texteditor禁用返回键
我想知道如何在Swiftui中的键盘中禁用“返回”键?
我需要一个支持多行(约140个字符)的文本字段,因此我发现可以使用Texteditor。问题在于我找不到如何将板上的“返回”键更改为“完成”或简单地将其禁用。
有人知道该怎么做吗?
这是一些代码:
@State var annotationText = "Say something..."
//
TextEditor(text: $annotationText)
.onReceive(annotationText.publisher.collect()) {
annotationText = String($0.prefix(140))
}
.onTapGesture {
if annotationText == "Say something..." {
annotationText = ""
}
}
.frame(height: 50)
I was wondering how I can disable the "return" key in the keyboard for TextEditor in SwiftUI?
I need a TextField that supports multiple lines (around 140 characters) so I found that I can use TextEditor. The problem is that I can't find out how to change the "return" key on the board to "Done" or simply disable it.
Does anyone know how to do this?
Here's some code:
@State var annotationText = "Say something..."
//
TextEditor(text: $annotationText)
.onReceive(annotationText.publisher.collect()) {
annotationText = String($0.prefix(140))
}
.onTapGesture {
if annotationText == "Say something..." {
annotationText = ""
}
}
.frame(height: 50)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过手动获取/设置绑定变量找到了此解决方案:
Found this solution by manually getting/setting the binding variable: