一个 SwiftUI 应用程序的欢迎界面,模仿了“欢迎使用 Xcode”窗口。
WelcomeWindow 兼容目标平台为 macOS 11+ 和 iOS 14+ 的应用程序。
WelcomeWindow
可作为 Swift Package 使用。要在您的项目中使用它,请将其添加到您项目的 Swift Packages 中
https://github.com/JUSTINMKAUFMAN/WelcomeWindow.git
请参考 Demo
应用程序(包含在此仓库中)以获取示例用法。
或者,可以按如下方式使用 WelcomeWindow
import SwiftUI
import WelcomeWindow
@main
struct WelcomeWindowDemoApp: App {
// Optionally track the hover state of the logo (macOS only)
@State var isHoveringLogo: Bool = false
private var logoView: AnyView {
AnyView(
Image(systemName: "qrcode.viewfinder")
.resizable()
.scaleEffect(isHoveringLogo ? 0.8 : 1.0)
.rotationEffect(Angle(degrees: isHoveringLogo ? 180.0 : 0.0))
.animation(.easeInOut, value: isHoveringLogo)
.onHover { isHoveringLogo = $0 }
)
}
@SceneBuilder var body: some Scene {
WindowGroup {
WelcomeWindow(
logoView: logoView,
titleText: "Welcome to App",
actions: [
WelcomeAction(
title: "Create a new project",
detail: "Create a new project",
systemImage: "plus.square",
imageColor: Color.red,
isEnabled: false,
onSelect: { print("Action triggered") }
),
WelcomeAction(
title: "Create a new project",
detail: "Create a new project",
systemImage: "plus.square",
imageColor: Color.green,
onSelect: { print("Action triggered") }
),
WelcomeAction(
title: "Create a new project",
detail: "Create a new project",
systemImage: "plus.square",
onSelect: { print("Action triggered") }
)
],
documentListTitle: "Recently Opened",
recentDocuments: [
RecentDocument(
name: "MyDocA",
detail: "/path/to/MyDocA",
contextMenu: {
AnyView(
VStack {
Button(
action: { print("Context Action A triggered") },
label: { Text("Context Action A") }
)
Button(
action: { print("Context Action B triggered") },
label: { Text("Context Action B") }
)
}
)
}
),
RecentDocument(
name: "MyDocB",
detail: "/path/to/MyDocB",
contextMenu: {
AnyView(
VStack {
Button(
action: { print("Context Action A triggered") },
label: { Text("Context Action A") }
)
Button(
action: { print("Context Action B triggered") },
label: { Text("Context Action B") }
)
}
)
}
),
RecentDocument(
name: "MyDocB",
detail: "/path/to/MyDocB",
systemImage: "plus.square",
contextMenu: {
AnyView(
VStack {
Button(
action: { print("Context Action A triggered") },
label: { Text("Context Action A") }
)
Button(
action: { print("Context Action B triggered") },
label: { Text("Context Action B") }
)
}
)
}
)
],
handleOpenDocument: { doc in print("Document opened: \(doc.name)") },
isHoveringLogo: $isHoveringLogo
)
}
}
}
Justin Kaufman, jmkauf@gmail.com
WelcomeWindow 在 MIT 许可证下可用。有关更多信息,请参见 LICENSE 文件。