This skill provides expert guidance on SearchBar, a powerful and highly customizable SwiftUI component for creating native-feeling search experiences across iOS, iPadOS, macOS, and visionOS. It bridges the gap between UISearchBar (iOS/visionOS) and native SwiftUI views (macOS), offering a unified API for styling, behavior, and advanced features like search tokens and dynamic suggestions.
UISearchBar) vs. macOS (custom SwiftUI). Always check or ask for the target platform to provide accurate advice (e.g., specific material effects or token behaviors).SearchBar modifiers (e.g., .searchBarStyle, .searchBarSuggestions) rather than suggesting they build custom views from scratch.SearchBar is fully localized and adapts to system languages automatically.@State for text and tokens.#if os(...) directives if necessary (though the library handles most internally).references/SearchBar.mdreferences/SearchBarStyle.mdreferences/SearchBarStyle.mdreferences/SearchBarStyle.mdreferences/SearchBarModifiers.md (.searchBarIconView)references/SearchBarDisplayModes.mdreferences/SearchBarModifiers.mdreferences/SearchBarModifiers.md (.searchBarIsFocused)references/SearchBarData.mdreferences/SearchBarData.mdreferences/SearchBarData.mdUISearchBar. Styling is consistent but underlying implementation differs..searchBarStyle(..., backgroundColor: .red). See references/SearchBarStyle.md..searchBarCancelButtonDisplayMode(.never). See references/SearchBarDisplayModes.md..searchBarMaterial(.glass). Note platform/version restrictions (iOS 26+). See references/SearchBarStyle.md.SearchBar(text: $text, prompt: "Search...")
.searchBarStyle(.rounded)
SearchBar(text: $text)
.searchBarStyle(.capsule, textColor: .white, tint: .blue, backgroundColor: .black.opacity(0.8))
.searchBarMaterial(.glass) // iOS 26+ (Experimental/Future)
SearchBar(text: $text)
.searchBarCurrentTokens($tokens)
.searchBarSuggestions($suggestions)
.searchBarEnableAutomaticSuggestionsFiltering(true)
SearchBar(text: $text)
.searchBarBeginEditingAction { print("Started") }
.searchBarEndEditingAction { print("Ended") }
.searchBarCancelButtonAction { print("Cancelled") }
SearchBar is integrated via Swift Package Manager.
https://github.com/SzpakKamil/SearchBar.git.import SearchBar in your Swift files.For detailed setup, see references/SearchBar.md.
SearchBar.md - General overview, setup, and initialization.SearchBarModifiers.md - Comprehensive list of all modifiers.SearchBarStyle.md - Styling, materials, corner styles, and scale.SearchBarDisplayModes.md - Cancel and Clear button behaviors.SearchBarData.md - Search Tokens and Suggestions._index.md - Index of all topics.共 1 个版本