展示

Swift iOS GitHub License GitHub Stars GitHub Forks

Showcase 是一个 Swift 包,旨在简化文档化和展示基于 SwiftUI 组件的过程。它为您的 SwiftUI 项目创建、组织和呈现文档提供了一种结构化的方法。 Showcase 提供了多种自定义选项和样式,用于呈现代码示例、预览等。

特性

要求

安装

Swift 包管理器

您可以使用 Swift 包管理器 轻松地将 Showcase 集成到您的 Xcode 项目中。 请按照以下步骤操作:

  1. 在 Xcode 中打开您的项目。
  2. 转到“File” -> “Swift Packages” -> “Add Package Dependency...”
  3. 出现提示时,输入以下 URL:https://github.com/ipedro/swiftui-showcase
  4. 选择您要使用的版本或分支。
  5. 单击“Finish”将包添加到您的项目中。

或者,您可以在 Package.swift 文件中将 Showcase 添加为依赖项

dependencies: [
    .package(url: "https://github.com/ipedro/swiftui-showcase", from: "0.3.0")
]

另请注意:不要忘记将 "Showcase" 添加为您的包目标的依赖项。

用法

  1. 在您的 SwiftUI 视图文件中导入 Showcase 模块

    import Showcase
  2. 使用 Topic 实例创建并构建您的 Showcase 主题。

展示

Showcase 视图用于显示您的 Showcase 主题。 这是一个例子:

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            // Create a Showcase with a Topic, e.g., .card
            Showcase(.mockCard)
                .navigationTitle("Component Showcase")
        }
    }
}

ShowcaseList

ShowcaseList 视图允许您列出 Showcase 主题的章节。 这是一个例子:

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            // Create a list with two chapters
            ShowcaseList(
                Chapter("Section 1", .card, .accordion),
                Chapter("Section 2", .button, .text)
            )
            .navigationTitle("Component Showcase")
        }
    }
}

ShowcaseNavigationView

ShowcaseNavigationView 视图提供对 Showcase 主题章节的导航。 这是一个例子:

import SwiftUI

struct ContentView: View {
    var body: some View {
        // Create a ShowcaseNavigationView with a Chapter and optional icon
        ShowcaseNavigationStack(
            ShowcaseChapter(
                "My Chapter", 
                Chapter("Section 1", .card, .accordion),
                Chapter("Section 2", .button, .text)
            )
        )
    }
}

许可

Showcase 在 MIT 许可下发布。 有关详细信息,请参阅 LICENSE

贡献

欢迎贡献! 请参阅我们的 贡献指南 以获取更多信息。

致谢

Showcase 由 Pedro Almeida 创建和维护。