V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
newkengsir
V2EX  ›  开源软件

PYSearch - iOS 中一款优雅的搜索控制器。

  •  
  •   newkengsir · 2016-10-26 11:38:15 +08:00 · 6273 次点击
    这是一个创建于 2747 天前的主题,其中的信息可能已经有所发展或是发生改变。

    PYSearch

    Features

    • 支持多种热门搜索风格
    • 支持多种搜索历史风格
    • 支持搜索建议
    • 支持搜索历史(记录)缓存
    • 支持使用 delegate 或者 block 完成搜索时的回调
    • 支持 CocoaPods

    Requirements

    • iOS 7.0 or later
    • Xcode 8.0 or later

    Contents

    效果图

    支持哪些风格

    热门搜索风格

    搜索历史

    如何使用 PYSearch

    • 使用 CocoaPods:
      • pod "PYSearch"
      • 导入主头文件#import <PYSearch.h>
    • 手动导入:
      • PYSearch文件夹中的所有文件拽入项目中
      • 导入主头文件#import "PYSearch.h"

    具体使用(详情见示例程序 PYSearchExample )

        // 1. 创建热门搜索数组
        NSArray *hotSeaches = @[@"Java", @"Python", @"Objective-C", @"Swift", @"C", @"C++", @"PHP", @"C#", @"Perl", @"Go", @"JavaScript", @"R", @"Ruby", @"MATLAB"];
        // 2. 创建搜索控制器
        PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:hotSeaches searchBarPlaceholder:@"搜索编程语言" didSearchBlock:^(PYSearchViewController *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];
    
    

    自定义 PYSearch

    通过设置 searchViewContoller 的对象属性值即可修改

    • 设置热门搜索风格(默认为 PYHotSearchStyleNormalTag )
    	// 设置热门搜索为彩色标签风格
    	searchViewController.hotSearchStyle = PYHotSearchStyleColorfulTag;
    
    • 设置搜索历史风格(默认为 PYSearchHistoryStyleCell )
    	// 设置搜索历史为带边框标签风格
    	searchViewController.searchHistoryStyle = PYSearchHistoryStyleBorderTag;
    
    • 隐藏搜索建议(默认为: NO )
    	// 隐藏搜索建议
    	searchViewController.searchSuggestionHidden = YES;
    

    期待

    • 如果您在使用过程中有任何问题,欢迎 issue me! 很乐意为您解答任何相关问题!
    • 与其给我点 star ,不如向我狠狠地抛来一个 BUG !
    • 如果想要参与这个项目的维护或者有好的设计风格,欢迎 pull request !
    • 如果您想要更多的接口来自定义或者建议 /意见,欢迎 issue me !我会根据大家的需求提供更多的接口!

    Licenses

    All source code is licensed under the MIT License.

    code4app

    2 条回复    2016-10-26 17:39:20 +08:00
    cyanbox
        1
    cyanbox  
       2016-10-26 14:02:49 +08:00
    赞!不过 py ?
    programdog
        2
    programdog  
       2016-10-26 17:39:20 +08:00
    66666
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   756 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:08 · PVG 05:08 · LAX 14:08 · JFK 17:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.