跳到正文

Button

原生 SwiftUI 按钮,支持文本、SF Symbol、语义角色和按下处理。

#导入

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

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

#用法

func SwiftUiButtonExample() *native.Node {
	return ui.SwiftUI.Host(
		ui.SwiftUIHostProps{MatchContents: true},
		func() *native.Node {
			return ui.SwiftUI.Button(ui.SwiftUIButtonProps{
				Label:       "Save",
				SystemImage: "checkmark",
				OnPress:     func(*native.Event) { fmt.Println("Saved") },
				Modifiers:   []ui.SwiftUIModifier{ui.SwiftUI.ButtonStyle("borderedProminent")},
			})
		},
	)
}

#API 参考

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

SwiftUI.Button

查看源码
ui.SwiftUI.Button(props SwiftUIButtonProps, children ...any) *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)
查看源码
Labelany—

Visible native SwiftUI control label.

any
查看源码
SystemImagestring—

SF Symbols name displayed with a SwiftUI button label.

string
查看源码
Rolestring—

Accessibility role override. Prefer the component’s built-in semantics.

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

Runs when the native SwiftUI button is activated.

func(*native.Event)
查看源码
Targetstring—

Destination associated with this navigation or link part.

string
查看源码
ChildrenComponent—

Content mounted inside the component. Compound child callbacks run after the parent context exists.

Component
查看源码