跳到正文

Toggle

受控的原生 SwiftUI 开关。

#导入

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

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

#用法

func SwiftUiToggleExample() *native.Node {
	on, setOn := ui.CreateSignal(true)
	return ui.SwiftUI.Host(
		ui.SwiftUIHostProps{MatchContents: true},
		func() *native.Node {
			return ui.SwiftUI.Toggle(ui.SwiftUIToggleProps{
				IsOn:         on,
				Label:        "Notifications",
				OnIsOnChange: func(next bool, _ *native.Event) { setOn(next) },
			})
		},
	)
}

#API 参考

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

SwiftUI.Toggle

查看源码
ui.SwiftUI.Toggle(props SwiftUIToggleProps) *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)
查看源码
IsOnany—

Controlled SwiftUI toggle value.

any
查看源码
Labelany—

Visible native SwiftUI control label.

any
查看源码
OnIsOnChangefunc(bool, *native.Event)—

Reports the value accepted by the native SwiftUI toggle.

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