我在SwiftUi中有一个文本编辑器,当用户返回或backspace时,我正在做一些自定义的事情。 texteditor(文字:$ item.text) 。 .onkeypress(

问题描述 投票:0回答:1

要实现“我想做的一件事的目标之一就是防止键入的第一个角色成为空间或返回/新线”,您可以
如示例代码:
使用`.onchange`

结构项目:可识别,hashable { 令ID:uuid = uuid() var text:string =“”

}
ios swift swiftui swiftui-texteditor
1个回答
0
投票
struct texteditorview:查看{

@State私人var item = item()
@focusstate private var focususedEtem:uuid?

var body: some View { TextEditor(text: $item.text) .focusable() .focused($focusedItem, equals: item.id) .frame(height: 222) .border(.red) .onChange(of: item.text) { if item.text.first == "\\n" || item.text.first == " " { item.text.removeFirst() } } }

}

-struct contentView:查看{

var身体:某些视图{
texteditorview()
}

}
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.