SymbolPicker Skill
Overview
This skill provides expert guidance on SymbolPicker, a native, customizable SwiftUI component for selecting SF Symbols on iOS, iPadOS, macOS, and visionOS. It mimics Apple’s native interface while offering extensive customization for colors, styles (filled/outlined), and behavior.
Agent Behavior (Follow These Rules)
- 1. Identify Platform Targets: SymbolPicker adapts to each platform (sheet on iOS, popover on iPad/Mac/visionOS). Always verify the target platform.
- Prioritize Modifiers: Direct users to the relevant
SymbolPicker modifiers (e.g., .symbolPickerSymbolsStyle, .symbolPickerDismiss) for customization. - Handle Colors Correctly: When discussing color selection, clarify if the user wants to use
[Double] (RGBA), SwiftUI Color, or SymbolColor. - Emphasize Accessibility: Highlight that SymbolPicker supports VoiceOver and Dynamic Type out of the box.
- Contextual Examples: Provide concise code snippets showing the
.symbolPicker modifier applied to a view (usually a Button or Image), with bindings for presentation and selection. - Cross-Platform Consistency: Remind users that the API is unified across platforms.
Project Settings
- - Deployment Targets: iOS 14.0+, iPadOS 14.0+, macOS 11.0+, visionOS 1.0+.
- Swift Version: Swift 5.9+.
- Xcode: Xcode 15.0+.
Quick Decision Tree
- 1. Setting up a basic symbol picker?
* Basic installation and concepts →
references/SymbolPicker.md
* To apply the modifier to a view → INLINECODE9
- 2. Picking symbols with color?
* To use different color binding types →
references/SymbolPickerView.md
* To understand the
SymbolColor model → INLINECODE12
- 3. Customizing appearance or behavior?
* Switching between filled/outlined icons →
references/SymbolPickerModifiers.md (
.symbolPickerSymbolsStyle)
* Controlling dismissal behavior →
references/SymbolPickerModifiers.md (
.symbolPickerDismiss)
Triage-First Playbook
- - "The picker isn't showing up."
* Check if
.symbolPicker(isPresented: ...) is attached to a view that is part of the hierarchy.
* Ensure the
isPresented binding is being toggled true.
- - "I want filled icons instead of outlines."
* Use
.symbolPickerSymbolsStyle(.filled).
- - "How do I close the picker immediately after selecting a symbol?"
* Use
.symbolPickerDismiss(type: .onSymbolSelect).
Core Patterns Reference
Basic Usage
CODEBLOCK0
With Color Selection
CODEBLOCK1
Integration Quick Guide
- 1. Add Package Dependency:
https://github.com/SzpakKamil/SymbolPicker.git (Min version 1.0.0). - Import:
import SymbolPicker. - Requirements: iOS 14.0+, macOS 11.0+, visionOS 1.0+.
Reference Files
Load these files as needed for specific topics:
- -
SymbolPicker.md - General overview, setup, and core benefits. SymbolPickerView.md - Detailed information on the picker view and its initializers.SymbolPickerModifiers.md - Customization of style (filled/outlined) and dismissal behavior.SymbolColor.md - Guide to using the SymbolColor enum and color bindings.SetUp.md - Step-by-step installation instructions.
SymbolPicker 技能
概述
本技能提供关于 SymbolPicker 的专业指导,这是一个原生、可定制的 SwiftUI 组件,用于在 iOS、iPadOS、macOS 和 visionOS 上选择 SF Symbols。它模仿苹果的原生界面,同时提供丰富的颜色、样式(填充/轮廓)和行为定制选项。
代理行为(遵循以下规则)
- 1. 识别平台目标: SymbolPicker 会根据不同平台进行调整(iOS 上为表单,iPad/Mac/visionOS 上为弹出窗口)。务必确认目标平台。
- 优先使用修饰符: 引导用户使用相关的 SymbolPicker 修饰符(例如 .symbolPickerSymbolsStyle、.symbolPickerDismiss)进行定制。
- 正确处理颜色: 在讨论颜色选择时,明确用户是想使用 [Double](RGBA)、SwiftUI Color 还是 SymbolColor。
- 强调无障碍性: 突出 SymbolPicker 开箱即支持 VoiceOver 和动态字体。
- 上下文示例: 提供简洁的代码片段,展示如何将 .symbolPicker 修饰符应用于视图(通常是 Button 或 Image),并包含展示和选择的绑定。
- 跨平台一致性: 提醒用户 API 在所有平台上保持一致。
项目设置
- - 部署目标: iOS 14.0+、iPadOS 14.0+、macOS 11.0+、visionOS 1.0+。
- Swift 版本: Swift 5.9+。
- Xcode: Xcode 15.0+。
快速决策树
- 1. 设置基本符号选择器?
* 基本安装和概念 → references/SymbolPicker.md
* 将修饰符应用于视图 → references/SymbolPickerView.md
- 2. 选择带颜色的符号?
* 使用不同的颜色绑定类型 → references/SymbolPickerView.md
* 理解 SymbolColor 模型 → references/SymbolColor.md
- 3. 自定义外观或行为?
* 在填充/轮廓图标之间切换 → references/SymbolPickerModifiers.md(.symbolPickerSymbolsStyle)
* 控制关闭行为 → references/SymbolPickerModifiers.md(.symbolPickerDismiss)
优先排查指南
* 检查 .symbolPicker(isPresented: ...) 是否附加在视图层次结构中的视图上。
* 确保 isPresented 绑定已被切换为 true。
* 使用 .symbolPickerSymbolsStyle(.filled)。
* 使用 .symbolPickerDismiss(type: .onSymbolSelect)。
核心模式参考
基本用法
swift
@State private var isPresented = false
@State private var icon = star
Button(选择图标) { isPresented = true }
.symbolPicker(isPresented: $isPresented, symbolName: $icon)
带颜色选择
swift
@State private var isPresented = false
@State private var icon = star.fill
@State private var color: Color = .red
Button(选择图标和颜色) { isPresented = true }
.symbolPicker(isPresented: $isPresented, symbolName: $icon, color: $color)
.symbolPickerSymbolsStyle(.filled)
.symbolPickerDismiss(type: .onSymbolSelect)
集成快速指南
- 1. 添加包依赖: https://github.com/SzpakKamil/SymbolPicker.git(最低版本 1.0.0)。
- 导入: import SymbolPicker。
- 要求: iOS 14.0+、macOS 11.0+、visionOS 1.0+。
参考文件
根据需要加载以下文件以获取特定主题:
- - SymbolPicker.md - 总体概述、设置和核心优势。
- SymbolPickerView.md - 关于选择器视图及其初始化器的详细信息。
- SymbolPickerModifiers.md - 样式(填充/轮廓)和关闭行为的定制。
- SymbolColor.md - 使用 SymbolColor 枚举和颜色绑定的指南。
- SetUp.md - 分步安装说明。