跳到正文

Picker

受控的 SwiftUI 选择器,支持菜单、分段、单选组和内联样式。

#导入

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

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

#用法

func SwiftUiPickerExample() *native.Node {
	value, setValue := ui.CreateSignal("list")
	return ui.SwiftUI.Host(
		ui.SwiftUIHostProps{MatchContents: true},
		func() *native.Node {
			return ui.SwiftUI.Picker(ui.SwiftUIPickerProps{
				Selection:         value,
				Options:           []ui.SwiftUIPickerOption{{Value: "list", Label: "List"}, {Value: "grid", Label: "Grid"}},
				OnSelectionChange: func(next string, _ *native.Event) { setValue(next) },
			})
		},
	)
}

#API 参考

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

SwiftUI.Picker

查看源码
ui.SwiftUI.Picker(props SwiftUIPickerProps) *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)
查看源码
Selectionany—

Controlled selection for a table, native picker, or color control.

any
查看源码
Optionsany—

Ordered native picker options.

any
查看源码
Labelany—

Visible native SwiftUI control label.

any
查看源码
Stylestring—

Reusable layout, typography, color, and interaction-state styles. Build with ui.Style() and compose with Merge.

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

Reports the selected native picker option or color.

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