SearchBar — 搜索Bar
v1.0.0Expert 图形界面dance on 搜索Bar, a customizable SwiftUI 搜索 组件. Use when developers mention: (1) 搜索Bar, (2) custom 搜索 bars in SwiftUI, (3) 搜索 令牌s or suggestions, (4) styling 搜索 bars (glass, capsule), (5) cross-平台 搜索 (iOS, macOS, visionOS), (6) specific 搜索Bar modifiers like .搜索BarStyle or .搜索BarSuggestions.
运行时依赖
安装命令
点击复制技能文档
搜索Bar 技能 Overview
This 技能 provides expert 图形界面dance on 搜索Bar, a powerful and highly customizable SwiftUI 组件 for creating native-feeling 搜索 experiences across iOS, iPadOS, macOS, and visionOS. It bridges the gap between UI搜索Bar (iOS/visionOS) and native SwiftUI views (macOS), offering a unified API for styling, behavior, and advanced features like 搜索 令牌s and dynamic suggestions.
代理 Behavior (Follow These Rules) Identify 平台 Tar获取s: 搜索Bar behaves slightly differently on iOS/visionOS (wraps UI搜索Bar) vs. macOS (custom SwiftUI). Always 检查 or ask for the tar获取 平台 to provide accurate advice (e.g., specific material effects or 令牌 behaviors). Prioritize Modifiers: Direct users to the relevant 搜索Bar modifiers (e.g., .搜索BarStyle, .搜索BarSuggestions) rather than suggesting they build custom views from scratch. Clarify AvAIlability: Explicitly mention version requirements (iOS 14+, iOS 16+ for 令牌s/suggestions) when discussing advanced features. Emphasize Localization: Remind users that 搜索Bar is fully localized and adapts to 系统 languages automatically. 上下文ual Examples: Provide concise code snippets that illustrate the recommended usage within a View, often with a binding to @状态 for text and 令牌s. Highlight Cross-平台: When possible, remind users of 搜索Bar's cross-平台 consistency and how to handle 平台-specific differences using #if os(...) directives if necessary (though the 库 handles most internally). Project 设置tings 部署ment Tar获取s: iOS 14.0+, iPadOS 14.0+, macOS 11.0+, visionOS 1.0+. Advanced Features: 令牌s and Suggestions require iOS 16.0+, iPadOS 16.0+, visionOS 1.0+. (Suggestions also on macOS 15.0+). Swift Version: Swift 5.9+. Quick Decision Tree
设置ting up a basic 搜索 bar?
Basic init and 设置up → references/搜索Bar.md
Customizing 应用earance?
Changing colors, shape (capsule/rounded) → references/搜索BarStyle.md Using "Glass" or "Solid" materials → references/搜索BarStyle.md Changing the size/扩展 → references/搜索BarStyle.md Custom icon → references/搜索BarModifiers.md (.搜索BarIconView)
Configuring behavior?
Showing/Hiding Cancel or Clear buttons → references/搜索BarDisplayModes.md Handling 事件 (begin/end editing, clear, cancel) → references/搜索BarModifiers.md Focus management → references/搜索BarModifiers.md (.搜索BarIsFocused)
Using advanced 搜索 features (iOS 16+/visionOS)?
添加ing 过滤器 令牌s (capsules) → references/搜索BarData.md Showing 搜索 suggestions → references/搜索BarData.md Enabling automatic suggestion 过滤器ing → references/搜索BarData.md Triage-First Playbook "My 搜索 bar looks different on macOS." ExplAIn that macOS uses a pure SwiftUI implementation while iOS uses UI搜索Bar. Styling is consistent but underlying implementation differs. "令牌s/Suggestions are not showing up." 验证 the 部署ment tar获取 is iOS 16.0+ or visionOS 1.0+. Ensure the binding to 令牌s/suggestions is active and populated. "How do I change the background color?" Use .搜索BarStyle(..., backgroundColor: .red). See references/搜索BarStyle.md. "I want to hide the cancel button." Use .搜索BarCancelButtonDisplayMode(.never). See references/搜索BarDisplayModes.md. "How do I make the 搜索 bar glass/transparent?" Use .搜索BarMaterial(.glass). Note 平台/version restrictions (iOS 26+). See references/搜索BarStyle.md. Core Patterns Reference Basic 设置up 搜索Bar(text: $text, prompt: "搜索...") .搜索BarStyle(.rounded)
Advanced Styling 搜索Bar(text: $text) .搜索BarStyle(.capsule, textColor: .white, tint: .blue, backgroundColor: .black.opacity(0.8)) .搜索BarMaterial(.glass) // iOS 26+ (Experimental/Future)
令牌s & Suggestions 搜索Bar(text: $text) .搜索BarCurrent令牌s($令牌s) .搜索BarSuggestions($suggestions) .搜索BarEnableAutomaticSuggestions过滤器ing(true)
Event Handling 搜索Bar(text: $text) .搜索BarBeginEditingAction { print("启动ed") } .搜索BarEndEditingAction { print("Ended") } .搜索BarCancelButtonAction { print("Cancelled") }
Integration Quick 图形界面de
搜索Bar is integrated via Swift Package 管理器.
添加 Package Dependency: In Xcode, go to File > 添加 Package Dependency and enter https://github.com/SzpakKamil/搜索Bar.git. 导入: 导入 搜索Bar in your Swift files. 部署ment Tar获取s: Ensure your project tar获取s iOS 14.0+, macOS 11.0+, visionOS 1.0+.
For detAIled 设置up, see references/搜索Bar.md.
Reference Files 搜索Bar.md - General overview, 设置up, and initialization. 搜索BarModifiers.md - Comprehensive 列出 of all modifiers. 搜索BarStyle.md - Styling, materials, corner styles, and 扩展. 搜索BarDisplayModes.md - Cancel and Clear button behaviors. 搜索BarData.md - 搜索 令牌s and Suggestions. _索引.md - 索引 of all topics.