🔍 An elegant search controller which replaces the UISearchController for iOS (iPhone & iPad) .

Last update: Jun 20, 2022



Apps Using Total Downloads
Build Status Pod Version Pod Platform Pod License

  • 🔍 An elegant search controller for iOS.

QQ chat room

 

Features

  • Support a variety of hot search style
  • Support a variety of search history style
  • Support a variety of search results display mode
  • Support a variety of search view controller display mode
  • Support search suggestions
  • Support search history (record) cache
  • Support callback using delegate or block completion search
  • Support CocoaPods
  • Support localization
  • Support vertical and horizontal screen on iPhone and iPad

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

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"

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];

Custom

  • Custom search suggestions display
// 1. Set dataSource
searchViewController.dataSource = self;
// 2. Implement dataSource method
  • Custom search result dispaly
// 1. Set searchResultShowMode
searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
// 2. Set searchResultController 
searchViewController.searchResultController = [[UIViewController alloc] init];
  • Set hotSearchStyle(default is PYHotSearchStyleNormalTag)
// Set hotSearchStyle
searchViewController.hotSearchStyle = PYHotSearchStyleColorfulTag;
  • Set searchHistoryStyle(default is PYSearchHistoryStyleCell)
// Set searchHistoryStyle
searchViewController.searchHistoryStyle = PYSearchHistoryStyleBorderTag;
  • Set searchHistoriesCachePath(default is PYSEARCH_SEARCH_HISTORY_CACHE_PATH)
// Set searchHistoriesCachePath
searchViewController.searchHistoriesCachePath = @"The cache path";
  • Set searchHistoriesCount(default is 20)
// Set searchHistoriesCount
searchViewController. searchHistoriesCount = 6;
  • Set searchResultShowMode(default is PYSearchResultShowModeCustom)
// Set searchResultShowMode
searchViewController.searchResultShowMode = PYSearchResultShowModeEmbed;
  • Set searchSuggestionHidden(deafult is NO)
// Set searchSuggestionHidden
searchViewController.searchSuggestionHidden = YES;

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.

GitHub

https://github.com/ko1o/PYSearch
Comments
  • 1. 关于"预留接口"和"用户自定义"等建议

    少年有为的作者, 你好! 最近我在使用你写的这个框架, 感觉非常棒, 功能封装的很好, 很多时候只需要几行代码就能完成一个大功能. 另外, 我在使用的过程中也有一些心得和痛点, 算是抛砖引玉, 献丑了🙈

    1. 关于命名, 我们先聊聊 iOS SDK 中 UISearchController 的一个初始化方法, - (instancetype)initWithSearchResultsController:(UIViewController *)searchResultsController;这其中涉及两个 controller, searchController 和 searchResultsController, 一个是搜索的主页面, 另一个是搜索的结果页面.

    在 PYSearch 中, 对应功能的类分别为 PYSearchViewController 和 PYSearchSuggestionViewController, 此外, 在 PYSearchViewController 中还有一个属性 searchResultController, 三者的分别代表"搜索的主页面", "搜索的结果页面", "某条搜索结果的详情页",

    这个时候用过 UISearchController 的用户可能就会迷惑---searchResultController 到底是搜索的结果页面 还是 某个搜索结果的详情页? PYSearchSuggestionViewController 和 searchResultController 有什么关系? 我在用的时候就产生了此类疑惑, 看了源码之后才明白 PYSearchSuggestionViewController 和 UISearchController 中的 searchResultsController 是一个意思. 我个人认为一个好的设计, 是不需要用户关心接口的实现的, 能见名知意.

    我建议这种情况下类或属性的命名和原生 API 保持类似的风格, PYSearchSuggestionViewController 可以改为 PYSearchResultsViewController 或 PYSearchResultsController; 而"某一条搜索结果的详情页" iOS 的 SDK 没有涉及, 这一步留给了用户自己在 searchResultsController 中处理. PYSearch 中对应的这个属性 searchResultController 可以改名为 resultDetailController.

    1. 关于"自定义"的痛点 这条内容又和 PYSearchResultsViewController 有关, 还得聊到 iOS SDK 中的 - (instancetype)initWithSearchResultsController:(UIViewController *)searchResultsController;. 在这个方法中, 搜索页面关联的 searchResultsController 是 UIViewController 类型的, 所以搜索结果页可以是单个 UITableView 页面, 也可以是复杂一点的一个 ScrollView 中嵌套的多个 tableView (比如"支付宝"的搜索页面), 总而言之, 这是一个用户可自定义的页面, 而不是局限为一个 tableView. 所以我建议搜索结果页的功能可以这样改: 搜索结果页的类型默认是UIViewController, 如果用户没有特别指定, 则只包含单个 tableView; 如果用户实现了自己的 searchResultsController, 则使用用户自定义的 controller 作结果页.

    2. 是一个预留控件的问题, 比如在 searchBar 的左边, 有时需要做一个可点击的下拉分类选择控件(参考淘宝的搜索页), searchBar 的右边, 有时需要显示一个语音输入按钮,根据用户的设置来决定是否显示, 不知道 PYSearch 目前也没有实现这个功能?

    Reviewed by Huang-Libo at 2017-01-04 08:38
  • 2. Logo Design Offer as Open Source Contribution

    Hello Sir. I'm a UI/UX and Graphics Designer. I want provide a logo for you. Would you mind if I propose a new logo design for your project as my Open Source Contribution?

    Thanks before.

    Reviewed by anharismail at 2018-05-22 03:33
  • 3. 搜索框错位

    2017-08-30 14 32 12 设置了Localization native development region为china,取消按钮还是cancel,代码将其修改为

    search?.navigationItem.rightBarButtonItem?.title = "取消"
    

    然后就出现如上图所示错位情况。

    另外A控制器 Present B(search):

    let nav = UINavigationController.init(rootViewController: search!)
            nav.modalPresentationStyle = .overCurrentContext
            nav.view.backgroundColor = UIColor.init(r: 80, g: 55, b: 50).withAlphaComponent(0.8)
            present(nav, animated: true, completion: nil)
    

    如果A navigationBar 是透明的,我如何设置search的navBar不透明,换言之让2个控制器的navBar颜色一致。

    还有个问题,假如有【本地文件】和【网络文件】2种类型可以搜索,当前的设计模式可以直接在search 这个view上添加2个segement进行切换吗?

    Reviewed by dongdong3344 at 2017-08-30 06:46
  • 4. 键盘存在与否,影响数据的整体显示

    问题:实现了delegate 并写了 didSelectHotSearchAtIndex 和 didSelectSearchHistoryAtIndex 方法,当点击搜索历史记录时,此时键盘是收起来的,那么弹出来的搜索建议不能显示完全,底部总有几个滚不上来,当我将键盘一直显示的时候,那么是可以完全显示的,但是不想键盘一直显示,然后这个问题不知道怎么解决。。。

    Reviewed by honeycao at 2017-03-07 03:15
  • 5. 用一个UINavigationController包了searchViewController,present出来后,出现如图问题

    问题描述

    用一个UINavigationController包了searchViewController,present出来后,出现如图问题,页面会置顶了

    代码如下: self.searchNav = [[UINavigationController alloc] initWithRootViewController:searchViewController]; [self presentViewController:self.searchNav animated:NO completion:nil];

    重现步骤

    图片

    预期结果

    实际结果

    受影响的设备

    版本信息

    • PYSearch:vX.X.X
    • Xcode:vX.X.X
    • macOS:vX.X.X
    • CocoaPods:vX.X.X
    Reviewed by CCBrother at 2019-04-24 16:15
  • 6. search suggestion selection requires two taps

    Search suggestion result selection is not working on first tap. The didSelectRowAtIndexPath() is not called on first tap. But works fine on second tap. Single tap worked fine when I commented the below, but not sure of the side effects. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradFrameDidShow:) name:UIKeyboardDidShowNotification object:nil];

    Reviewed by bvrr557 at 2021-03-10 03:40
  • 7. iOS 13闪退 pod下来的,直接presentViewController,崩溃

    *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI isEqualToString:]: unrecognized selector sent to instance 0x28204e300'

    Reviewed by xianquHuang at 2019-11-05 02:50
The famous iOS search bar with auto completion feature implemented.
The famous iOS search bar with auto completion feature implemented.

PRESENTATION This search bar will allow you to offer suggestions words to your users when they are looking for something using default iOS search bar.

May 10, 2022
⚡️ A library of widgets and helpers to build instant-search applications on iOS.
⚡️ A library of widgets and helpers to build instant-search applications on iOS.

By Algolia. InstantSearch family: InstantSearch iOS | InstantSearch Android | React InstantSearch | InstantSearch.js | Angular InstantSearch | Vue Ins

Jun 16, 2022
VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.
VKPinCodeView is simple and elegant UI component for input PIN. You can easily customise appearance and get auto fill (OTP) iOS 12 feature right from the box.

Features Variable PIN length Underline, border and custom styles The error status with / without shake animation Resetting the error status manually,

May 16, 2022
Elegant SwiftUI phone number textField.
Elegant SwiftUI phone number textField.

iPhoneNumberField ☎️ Format phone numbers as they're typed—entirely in SwiftUI. ?? Get Started | Examples | Customize | Features | Install | And it's

Jun 26, 2022
🔍 RAMReel is a UI controller that allows you to choose options from a list.
🔍 RAMReel is a UI controller that allows you to choose options from a list.

REEL SEARCH Reel Search is a Swift UI controller that allows you to choose options from a list We specialize in the designing and coding of custom UI

Jun 19, 2022
VMaskTextField is a library which create an input mask for iOS.
VMaskTextField is a library which create an input mask for iOS.

VMaskTextField An inputmask helps the user with the input by ensuring a predefined format. This can be useful for dates, numerics, phone numbers etc U

May 16, 2022
A custom TextField with a switchable icon which shows or hides the password and enforce good password policies
A custom TextField with a switchable icon which shows or hides the password and enforce good password policies

PasswordTextField A custom TextField with a switchable icon which shows or hides the password and enforces good password policies, written in Swift. ⭐

Apr 26, 2022
An auto-layout base UITextView subclass which automatically grows with user input and can be constrained by maximal and minimal height - all without a single line of code

Deprecated This library is no longer maintained and is deprecated. The repository might be removed at any point in the future. MBAutoGrowingTextView A

Jan 13, 2022
Text entry controls which contain a built-in title/label so that you don't have to add a separate title for each field.
Text entry controls which contain a built-in title/label so that you don't have to add a separate title for each field.

FloatLabelFields Overview Installation Via Interface Builder Via Code Credits Additional References Questions Overview FloatLabelFields is the Swift i

May 16, 2022
A customisable view for entering arbitrary length pins, codes or passwords in iOS. Supports iOS 12 one time codes.
A customisable view for entering arbitrary length pins, codes or passwords in iOS. Supports iOS 12 one time codes.

CBPinEntryView CBPinEntryView is a view written in Swift to allow easy and slick entry of pins, codes or passwords. It allows backspacing, dismissal o

May 2, 2022
AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.
AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

Jun 14, 2022
A SwiftUI TextField with a prompt (or placeholder) that floats above the text field when active or not empty. Requires iOS 15.
A SwiftUI TextField with a prompt (or placeholder) that floats above the text field when active or not empty. Requires iOS 15.

FloatingPromptTextField A prompt is the label in a text field that informs the user about the kind of content the text field expects. In a default Tex

May 31, 2022
Focus text field in SwiftUI dynamically and progress through form using iOS keyboard.
Focus text field in SwiftUI dynamically and progress through form using iOS keyboard.

Focuser Focuser allows to focus SwiftUI text fields dynamically and implements ability move go through the form using Keyboard for iOS 13 and iOS 14.

Jun 3, 2022
Provides a SwiftUI multi-line TextView implementation including support for auto-sizing. (iOS)

TextView Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ Provides a SwiftUI multi-line TextView implementation with supp

Jun 27, 2022
Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen in Apple's TV & TestFlight iOS apps.
Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen in Apple's TV & TestFlight iOS apps.

SwiftUI Matched Inline Title Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen i

Mar 21, 2022
iOS 15 0-day exploit (still works in 15.0.2)

Nehelper Wifi Info 0-day (iOS 15.0) I've updated this code to avoid using Private API directly. Read more in my blog post. However, that means that no

Jun 14, 2022
iOS 15 0-day exploit (still works in 15.0.2)

nehelper enumerate installed apps 0-day (iOS 15.0) I've updated this code to avoid using Private API directly. Read more in my blog post. However, tha

Jun 10, 2022
iOS gamed exploit (fixed in 15.0.2)

iOS gamed exploit (fixed in 15.0.2) Update: Apple has quietly fixed this in iOS 15.0.2 without any kind of public acknowledgement or credit. Any app i

Jun 10, 2022
UITextfield subclass with autocomplete menu. For iOS.
UITextfield subclass with autocomplete menu. For iOS.

MLPAutoCompleteTextField "We believe that every tap a user makes drains a tiny bit of their energy and patience. Typing is one of the biggest expendit

Jun 16, 2022