一系列美观且可重用的 SwiftUI 组件。
将以下行添加到您的 Package.swift
文件中的依赖项中
.package(url: "https://github.com/Talljack/Cooponent.git", from: "1.0.0")
然后将 "Cooponent" 作为您目标的依赖项包含进去
.target(
name: "YourTarget",
dependencies: ["Cooponent"]
)
import SwiftUI
import Cooponent
struct ContentView: View {
enum Tab: String, SegmentItem {
case home = "house.fill"
case search = "magnifyingglass"
case profile = "person.fill"
case settings = "gear"
}
@State private var selectedTab: Tab = .home
var body: some View {
// Default style with icons
SegmentedControl(
tabs: [.home, .search, .profile, .settings],
activeTab: $selectedTab,
activeTint: Color.blue,
inactiveTint: Color.gray
) { size in
Capsule()
.fill(Color.blue.opacity(0.2))
}
.frame(height: 50)
// Text mode
SegmentedControl(
tabs: [.home, .search, .profile, .settings],
activeTab: $selectedTab,
displayAsText: true,
font: .headline,
activeTint: Color.white,
inactiveTint: Color.gray
) { size in
RoundedRectangle(cornerRadius: 10)
.fill(Color.blue)
}
.frame(height: 45)
}
}
本项目根据 MIT 许可证授权 - 详细信息请参阅 LICENSE 文件。