一个能让你添加一个自定义颜选器的 Swift 包,灵感来自 Apple 提醒事项 App

封面

ColorGrid

通过集成一个完全可定制的颜色选择器(灵感来自 Apple Reminders 应用程序),来增强你的 SwiftUI 应用。

📝 要求

  • iOS 14.0+

⬇️ 安装

🔨 适用于 Xcode 项目

  1. 在 Xcode 中,从文件菜单中选择添加包
  2. 在搜索字段中输入https://github.com/BaherTamer/ColorGrid
  3. 点击添加包(将依赖项规则设置为直到下一个主要版本)
  4. 添加包后,你将能够使用在你的项目中导入ColorGrid
import ColorGrid

📦 适用于 Swift 包

在你的Package.swift中添加一个依赖项

dependencies: [
  .package(url: "https://github.com/BaherTamer/ColorGrid.git", from: "1.0.0")
]

⚙️ 配置

ColorGrid 允许你定义一些配置以满足你的需求。

public struct CGPicker: View {

    @Binding public var selection: Color
    
    private let colors: [Color]
    private let columns: [GridItem]
    private let icon: CGIcon
    
    public init(colors: [Color], selection: Binding<Color>, columns: Int = 6, icon: CGIcon = .circle) {
        self._selection = selection
        
        self.colors = colors
        self.columns = Array(repeating: GridItem(.flexible()), count: columns)
        self.icon = icon
    }

}

🎨 示例

import ColorGrid
import SwiftUI

// Content Example
struct ContentView: View {
    
    private let colors: [Color] = [.red, .orange, .yellow, .pink, .green, .blue, .purple, .gray] 
    @State private var selectedColor: Color = .red
    
    var body: some View {
        VStack(reminderColorSwift