列表占位符

一个库,用于在 SwiftUI 列表为空时呈现可自定义的占位符视图。它提供了一种简单而方便的方式,通过在没有内容可显示时显示相关信息或 UI 元素来增强用户体验。

安装

需要 iOS 14+、macOS 11+、watchOS 7+ 或 tvOS 14+。

Swift 包管理器

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

  1. 在 Xcode 中,转到“File”(文件)-> “Swift Packages”(Swift 包)-> “Add Package Dependency…”(添加包依赖项…)。
  2. 输入仓库 URL:https://github.com/javiergalera98/ListPlaceholder
  3. 指定您要使用的版本或分支。
  4. Xcode 将解析该包,您可以选择要添加 ListPlaceholder 的目标。

用法

要在 SwiftUI 中呈现列表占位符,请使用 .placeholder(for: items, content: view) 修饰符。

import SwiftUI
import ListPlaceholder

struct ContentView: View {
    @State var contacts: [String] = []
    
    var body: some View {
        List {
            ForEach(contacts, id: \.self) { contact in
                Text(contact)
            }
        }
        .placeholder(for: contacts) {
            Text("No contacts registered.")
                .foregroundStyle(Color.secondary)
        }
    }
}

社区

作者 贡献 需要帮助?
ListPlaceholder 由 Javier 创建。 欢迎所有贡献。只需 fork 这个仓库,然后发起一个 pull request。 打开一个 issue。您也可以在 Twitter 上私信我。或者阅读源代码 - 其中有很多注释。

许可证

MIT License

Copyright (c) 2023 Javier Galera.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Stats