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

Overview



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.

Comments
  • 关于

    关于"预留接口"和"用户自定义"等建议

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

    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 目前也没有实现这个功能?

    opened by Huang-Libo 15
  • Logo Design Offer as Open Source Contribution

    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.

    opened by anharismail 7
  • 搜索框错位

    搜索框错位

    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进行切换吗?

    opened by dongdong3344 6
  • 键盘存在与否,影响数据的整体显示

    键盘存在与否,影响数据的整体显示

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

    opened by honeycao 6
  • 用一个UINavigationController包了searchViewController,present出来后,出现如图问题

    用一个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
    opened by CCBrother 3
  • 无法设置导航栏返回按钮的样式

    无法设置导航栏返回按钮的样式

    从A页面(隐藏了navigationController)push到PYSearchViewController后,显示导航栏按钮图标和文字都是系统的,自己设定的不起作用,demo里的也是这样,用了很多办法不能解决,请问咋整啊

    setup方法里的self.navigationItem.leftBarButtonItem各种设置没用。。。。

    IMG_2400

    opened by littleZhangqq 0
  • search suggestion selection requires two taps

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

    opened by bvrr557 0
Releases(0.9.1)
  • 0.9.1(Oct 28, 2018)

    Fixed

    • Fixed #175 which when you enter the search result and then click back, the left back button and the arrow move left.
    • Fixed layout for navigation items by @baocang.
    • Fixed input cursor for searchBar by @baocang.
    Source code(tar.gz)
    Source code(zip)
  • 0.9.0(Jun 17, 2018)

    Added

    • Added searchBarCornerRadius to set cornerRadius of _UISearchBarSearchFieldBackgroundView
    • Added showKeyboardWhenReturnSearchResult property (#170) by @xiao99xiao
    Source code(tar.gz)
    Source code(zip)
  • 0.8.9(May 28, 2018)

  • 0.8.8(Dec 20, 2017)

  • 0.8.7(Nov 16, 2017)

    Fixed

    • Fixed a blank question at the bottom of searchSuggestionView on iOS 11.
    • Fixed #131 which the search bar deformation on iOS 11.

    Updated

    • Updated README.md
    Source code(tar.gz)
    Source code(zip)
  • 0.8.6(Nov 6, 2017)

  • 0.8.5(Oct 19, 2017)

  • 0.8.4(Sep 23, 2017)

  • 0.8.3(Aug 23, 2017)

  • 0.8.2(Jun 20, 2017)

  • 0.8.1(Jun 17, 2017)

  • 0.8.0(Apr 14, 2017)

    Fixed

    • Fixed #77 which don't display search suggestion view on the first time when custom search suggestion view.

    Optimized

    • Make the code international and elegant.
    Source code(tar.gz)
    Source code(zip)
  • 0.7.6(Apr 7, 2017)

  • 0.7.5(Mar 27, 2017)

    Fixed

    • Fixed #70 which there is a problem with the displayed results when navigationController.navigationBar.translucent is NO.
    • Fixed #72 which some display problems about custom cell.
    Source code(tar.gz)
    Source code(zip)
  • 0.7.4(Mar 23, 2017)

    Fixed

    • Fixed #68 which custom cache path is invalid in the closeDidClick: method.
    • Fixed #69 which hot search can not click when emptying search history and swapHotSeachWithSearchHistory is YES.
    Source code(tar.gz)
    Source code(zip)
  • 0.7.3(Mar 15, 2017)

    Fixed

    • Fixed #62 Use searchViewController:didSearchWithsearchBar:searchText: and the search record will not be saved.
    • Fixed #65 which search history is not displayed when hotSearches == nil.
    • Fixed #64 which remove all space on the search text .

    Deleted

    • Deleted UITableViewDataSource from protocols which the PYSearchViewControllerDataSource comply.

    Added

    • Added removeSpaceOnSearchString to control whether to remove space of the search text. Default is YES
    Source code(tar.gz)
    Source code(zip)
  • 0.7.2(Mar 2, 2017)

    Fixed

    • Fixed changes in other popular search label (PYHotSearchStyleRankTag, PYHotSearchStyleRectangleTag) mode, click the clear button didn't refresh the UI
      • Implemented by lzzhoujielun in #59.

    Update

    • Updated resources of PYSearch.bundle.
    Source code(tar.gz)
    Source code(zip)
  • 0.7.1(Feb 24, 2017)

  • 0.7.0(Feb 16, 2017)

  • 0.6.0(Feb 15, 2017)

    Fixed

    • Fixed the display of view when click on any of the hopSearchs to jump to the next view and click Back in #52.
    • Fixed [UIImage imageNamed: inBundle: compatibleWithTraitCollection:] just for iOS 8 or later
      • Implemented by hirat in #55.

    Added

    • Supported swap hotSearch with searchHistory when PYSearchHistoryStyle != PYSearchHistoryStyleCell.
    Source code(tar.gz)
    Source code(zip)
  • 0.5.9(Feb 11, 2017)

  • 0.5.8(Feb 8, 2017)

  • 0.5.7(Jan 20, 2017)

  • 0.5.6(Jan 18, 2017)

  • 0.5.5(Jan 9, 2017)

    Fixes

    • Fixed #42 hotSearch title and searchHistory title show overlap

    Features

    • Support customize the search history title and clear the search history
    Source code(tar.gz)
    Source code(zip)
  • 0.5.4(Jan 9, 2017)

  • 0.5.3(Jan 5, 2017)

    Features

    • Add showSearchResultWhenSearchTextChanged to control the display of embedded search results when search text did changed.
    • Add showSearchResultWhenSearchBarRefocused to control the display of embedded search results when the search bar did refocused.
    Source code(tar.gz)
    Source code(zip)
  • 0.5.2(Jan 3, 2017)

  • 0.5.1(Jan 3, 2017)

  • 0.5.0(Dec 26, 2016)

Owner
mamba
Just do iT.
mamba
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.

Boisney Philippe 182 Dec 23, 2022
⚡️ 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

Algolia 568 Jan 4, 2023
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,

Vladimir Kokhanevich 95 Nov 24, 2022
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

Seyed Mojtaba Hosseini Zeidabadi 358 Dec 30, 2022
🔍 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

Ramotion 2.5k Dec 21, 2022
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

Vinícius Oliveira 384 Jul 20, 2022
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. ⭐

Chris Jimenez 304 Dec 29, 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

Matej Balantič 125 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.

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

Fahim Farook 1.2k Jan 4, 2023
An `NSTextField` that specifies a maximum count after which text is highlighted to indicate an overflow

DSFMaxLengthDisplayTextField An NSTextField that specifies a maximum count after which text is highlighted to indicate an overflow Why? I always liked

Darren Ford 3 Aug 1, 2022
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

Chris Byatt 183 Dec 5, 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.

Abdelrhman Kamal 79 Jan 3, 2023
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

Emilio Peláez 43 Nov 3, 2022
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.

Art Technologies 118 Dec 25, 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

SwiftUI+ 51 Jan 3, 2023
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

Seb Jachec 19 Oct 9, 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

null 166 Nov 17, 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

null 158 Nov 19, 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

null 436 Dec 26, 2022