pod "HJWSearch"
#import <HJWSearch.h>
HJWSearch
文件夹中的所有文件拖入项目中#import "HJWSearch.h"
// 1. 创建热门搜索数组
NSArray *hotSeaches = @[@"Java", @"Python", @"Objective-C", @"Swift", @"C", @"C++", @"PHP", @"C#", @"Perl", @"Go", @"JavaScript", @"R", @"Ruby", @"MATLAB"];
// 2. 创建搜索控制器
HJWSearchViewController *searchViewController = [HJWSearchViewController searchViewControllerWithHotSearches:hotSeaches searchBarPlaceholder:@"搜索编程语言" didSearchBlock:^(HJWSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
// 开始(点击)搜索时执行以下代码
// 如:跳转到指定控制器
[searchViewController.navigationController pushViewController:[[UIViewController alloc] init] animated:YES];
}];
// 3. 跳转到搜索控制器
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
[self presentViewController:nav animated:NO completion:nil];
// 设置热门搜索为彩色标签风格
searchViewController.hotSearchStyle = HJWHotSearchStyleColorfulTag;
// 设置搜索历史为带边框标签风格
searchViewController.searchHistoryStyle = HJWSearchHistoryStyleBorderTag;
// 隐藏搜索建议
searchViewController.searchSuggestionHidden = YES;
所有源代码均免费许可使用MIT许可证。