跳到正文

TextField

受控的原生 SwiftUI 文本字段,提供编辑和提交回调。

#导入

从 github.com/egoist/quickgui/go/ui 导入 ui。

import (
	"github.com/egoist/quickgui/go/native"
	"github.com/egoist/quickgui/go/ui"
)

#用法

func SwiftUiTextFieldExample() *native.Node {
	text, setText := ui.CreateSignal("")
	return ui.SwiftUI.Host(
		ui.SwiftUIHostProps{MatchContents: true},
		func() *native.Node {
			return ui.SwiftUI.TextField(ui.SwiftUITextFieldProps{
				Value:         text,
				Placeholder:   "Enter text",
				OnValueChange: func(next string, _ *native.Event) { setText(next) },
			})
		},
	)
}

#API 参考

展开条目查看说明和完整签名。短横线表示声明中未记录默认值。

SwiftUI.TextField

查看源码
ui.SwiftUI.TextField(props SwiftUITextFieldProps) *native.Node
TestIDany—

Stable identifier for native automation and tests.

any
查看源码
Modifiersany—

Ordered SwiftUI view modifiers applied to the hosted control.

any
查看源码
Reffunc(*native.Node)—

Receives the retained native node after construction. Keep imperative work in event or lifecycle callbacks.

func(*native.Node)
查看源码
Valueany—

The current controlled value. Update application state from the change callback to accept a new value.

any
查看源码
Placeholderany—

Hint displayed while the text value is empty.

any
查看源码
OnValueChangefunc(string, *native.Event)—

Reports an accepted value change. Use the callback payload to update controlled state.

func(string, *native.Event)
查看源码
OnSubmitfunc(*native.Event)—

Called when the control submits its current value.

func(*native.Event)
查看源码