🔍 一个优雅的iOS搜索控制器。
QQ聊天室
特性
- 支持多种热门搜索样式
- 支持多种搜索历史样式
- 支持多种搜索结果显示方式
- 支持多种搜索视图控制器显示方式
- 支持搜索建议
- 支持搜索历史(记录)缓存
- 支持使用代理或块完成搜索回调
- 支持CocoaPods
- 支持本地化
- 支持iPhone和iPad的垂直和水平屏幕
要求
- iOS 7.0或更高版本
- Xcode 7.0或更高版本
架构
主要
PYSearch
PYSearchConst
PYSearchViewController
PYSearchSuggestionViewController
分类
UIColor+PYSearchExtension
UIView+PYSearchExtension
NSBundle+PYSearchExtension
内容
渲染
样式
热门搜索样式
搜索历史样式
如何使用
- 使用CocoaPods
pod "PYSearch"
- 导入主文件:
#import <PYSearch.h>
- 手动导入:
- 将
文件夹中的所有文件拖到项目中 - 导入主文件:
#import "PYSearch.h"
- 将
详细信息(查看示例程序 PYSearchExample 的详细信息)
// 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];
自定义
- 自定义搜索建议显示
// 1. Set dataSource
searchViewController.dataSource = self;
// 2. Implement dataSource method
- 自定义搜索结果显示
// 1. Set searchResultShowMode
searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
// 2. Set searchResultController
searchViewController.searchResultController = [[UIViewController alloc] init];
- 设置 hotSearchStyle(默认为 PYHotSearchStyleNormalTag)
// Set hotSearchStyle
searchViewController.hotSearchStyle = PYHotSearchStyleColorfulTag;
- 设置 searchHistoryStyle(默认为 PYSearchHistoryStyleCell)
// Set searchHistoryStyle
searchViewController.searchHistoryStyle = PYSearchHistoryStyleBorderTag;
- 设置 searchHistoriesCachePath(默认为 PYSEARCH_SEARCH_HISTORY_CACHE_PATH)
// Set searchHistoriesCachePath
searchViewController.searchHistoriesCachePath = @"The cache path";
- 设置 searchHistoriesCount(默认为 20)
// Set searchHistoriesCount
searchViewController. searchHistoriesCount = 6;
- 设置搜索结果显示模式(默认为 PYSearchResultShowModeCustom)
// Set searchResultShowMode
searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
- 设置 searchSuggestionHidden(默认为否)
// Set searchSuggestionHidden
searchViewController.searchSuggestionHidden = YES;
希望
- 如果在过程中有任何问题或想要更多可定制的接口,你可以向我提交问题!
- 与其给我点星,不如向我提交一个bug!
- 如果您想参与维护此项目或拥有优秀的设计风格,欢迎提出pull request!
- 如果您在使用过程中感到稍有不适,请联系我QQ:499491531或Email:[email protected]。
- 希望我们一起改进此项目,让它变得更强,能满足大多数用户的需求!
许可
所有源代码均采用 MIT 许可证。