- 🔍 An elegant search controller for iOS.
Features
- Support a variety of hot search style
- Support a variety of search history style
- Support a variety of search results display mode
- Support search suggestions
- Support search history (record) cache
- Support callback using delegate or block completion search
- Support CocoaPods
- Support localization
Requirements
- IOS 7.0 or later
- Xcode 7.0 or later
Architecture
Main
PYSearch
PYSearchConst
PYSearchViewController
PYSearchSuggestionViewController
Category
UIColor+PYSearchExtension
UIView+PYSearchExtension
NSBundle+PYSearchExtension
Contents
-
Getting Started
- Renderings
- Styles
-
Usage
- How to use
- Details (See the example program PYSearchExample for details)
- Custom
-
Hope
Renderings
Styles
Hot search style
Search history style
How to use
- Use CocoaPods:
pod "PYSearch"
- Import the main file:
#import <PYSearch.h>
- Manual import:
- Drag All files in the
PYSearch
folder to project - Import the main file:
#import "PYSearch.h"
- Drag All files in the
Details (See the example program PYSearchExample for details)
// 1. Create hotSearches array
NSArray *hotSeaches = @[@"Java", @"Python", @"Objective-C", @"Swift", @"C", @"C++", @"PHP", @"C#", @"Perl", @"Go", @"JavaScript", @"R", @"Ruby", @"MATLAB"];
// 2. Create searchViewController
PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:hotSeaches searchBarPlaceholder:@"Search programming language" didSearchBlock:^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
// Call this Block when completion search automatically
// Such as: Push to a view controller
[searchViewController.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
}];
// 3. present the searchViewController
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
[self presentViewController:nav animated:NO completion:nil];
Copy the code
Custom
- Custom search suggestions display
// 1. Set dataSource
searchViewController.dataSource = self;
// 2. Implement dataSource methodCopy the code
- Custom search result dispaly
// 1. Set searchResultShowMode
searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
// 2. Set searchResultController
searchViewController.searchResultController = [[UIViewController alloc] init];Copy the code
- The Set hotSearchStyle (default is PYHotSearchStyleNormalTag)
// Set hotSearchStyle
searchViewController.hotSearchStyle = PYHotSearchStyleColorfulTag;Copy the code
- Set searchHistoryStyle (default is PYSearchHistoryStyleCell)
// Set searchHistoryStyle
searchViewController.searchHistoryStyle = PYSearchHistoryStyleBorderTag;Copy the code
- Set searchHistoriesCachePath (default is PYSEARCH_SEARCH_HISTORY_CACHE_PATH)
// Set searchHistoriesCachePath
searchViewController.searchHistoriesCachePath = @"The cache path";Copy the code
- Set searchHistoriesCount (default is 20)
// Set searchHistoriesCount
searchViewController. searchHistoriesCount = 6;Copy the code
- The Set searchResultShowMode (default is PYSearchResultShowModeCustom)
// Set searchResultShowMode
searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;Copy the code
- Set searchSuggestionHidden (deafult is NO)
// Set searchSuggestionHidden
searchViewController.searchSuggestionHidden = YES;Copy the code
Hope
- If you have any questions during the process or want more interfaces to customize, you can issues me!
- Instead of giving me star, it is better to throw a bug to me!
- If you want to participate in the maintenance of this project or have a good design style, welcome to pull request!
- If you feel slightly discomfort in use, please contact me QQ:499491531 or Email:[email protected].
- Hope to improve this project together, let it become more powerful, able to meet the needs of most users!
Licenses
All source code is licensed under the MIT License.