为 SwiftUI 提供的简单且可定制的标签列表视图
在你的 Package.swift
中添加 SwiftUICustomTagListView
作为依赖项。
.package(name: "SwiftUICustomTagListView", url: "https://github.com/chitomo12/SwiftUICustomTagListView.git")
在你的 Podfile
中添加 SwiftUICustomTagListView
。
pod 'SwiftUICustomTagListView'
struct SampleView: View {
let data: [SampleTagViewData] = [
.init(text: "#Technology", color: Color(hex: "#ff4d4d")),
.init(text: "#News", color: Color(hex: "#b33636")),
.init(text: "#Politics", color: Color(hex: "#ff944d")),
.init(text: "#Breaking", color: Color(hex: "#ff4dd3")),
.init(text: "#Global", color: Color(hex: "#b33693")),
]
var views: [SwiftUICustomTagView<SampleTagView>] {
self.data.map { data in
SwiftUICustomTagView(content: {
SampleTagView(data: data)
})
}
}
var body: some View {
SwiftUICustomTagListView(views, horizontalSpace: 8, verticalSpace: 8)
.frame(width: 240, height: 220)
}
}
// MARK: - Define your own component
struct SampleTagView: View {
let data: SampleTagViewData
var body: some View {
Text(data.text)
.font(.title2)
.onTapGesture {
print("[Pressed] \(data.text)")
}
.foregroundColor(.white)
.padding(.all, 8)
.background(LinearGradient(
gradient: Gradient(colors: [data.color, data.color.opacity(0.6)]),
startPoint: .top,
endPoint: .bottom))
.cornerRadius(7)
}
}
struct SampleTagViewData {
let text: String
let color: Color
}
SwiftUICustomTagListView
基于 MIT 许可证发布。详情请查看 LICENSE 文件。