The famous iOS search bar with auto completion feature implemented.

Overview

Platform Language License

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. Enjoy it !

DEMO

Two ways to use this lib :

  • One with a simple array of string (Array<String>)
  • The other with an array of custom object (Array<ModernSearchBarModel>) if you want to get image of each row from an url.
SIMPLE ADVANCED

INSTALLATION

CocoaPods

You can use CocoaPods to install ModernSearchBar by adding it to your Podfile:

pod 'ModernSearchBar'

Manually

  1. Download and drop all *.swift files contained in Pod folder in your project.
  2. Don't forget to import the assets folder too.
  3. Enjoy !

USAGE

1 - Configure StoryBoard (Custom Class)

2 - Configure ViewController

//Import lib on the top of ViewController
import ModernSearchBar

//Create an IBOutlet from your searchBar
 @IBOutlet weak var modernSearchBar: ModernSearchBar!

//Extend your ViewController with 'ModernSearchBarDelegate'
class ViewController: UIViewController, ModernSearchBarDelegate

//Implement the delegation
self.modernSearchBar.delegateModernSearchBar = self

//Set datas to fill the suggestionsView of the searchbar.
//Two ways (you have to choose only one, you can't implement both obviously)

// 1 - With an Array<String>
var suggestionList = Array<String>()
suggestionList.append("Onions")
suggestionList.append("Celery")

self.modernSearchBar.setDatas(datas: suggestionList)

// 2 - With custom Array<ModernSearchBarModel>
var suggestionListWithUrl = Array<ModernSearchBarModel>()
suggestionListWithUrl.append(ModernSearchBarModel(title: "Alpha", url: "https://github.com/PhilippeBoisney/ModernSearchBar/raw/master/Examples%20Url/exampleA.png"))
suggestionListWithUrl.append(ModernSearchBarModel(title: "Bravo", url: "https://github.com/PhilippeBoisney/ModernSearchBar/raw/master/Examples%20Url/exampleB.png"))

self.modernSearchBar.setDatasWithUrl(datas: suggestionListWithUrl)

DELEGATE

ModernSearchBarDelegate inherit from UISearchBarDelegate, so you can find commons methods you already use in your project. Also, I add those methods to handle click actions on suggestionsView.

///Called if you use String suggestion list
func onClickItemSuggestionsView(item: String) {
   print("User touched this item: "+item)
}

///Called if you use Custom Item suggestion list
func onClickItemWithUrlSuggestionsView(item: ModernSearchBarModel) {
   print("User touched this item: "+item.title+" with this url: "+item.url.description)
}

///Called when user touched shadowView
func onClickShadowView(shadowView: UIView) {
   print("User touched shadowView")
}

CUSTOMIZING

//Modify shadows alpha
self.modernSearchBar.shadowView_alpha = 0.8

//Modify the default icon of suggestionsView's rows
self.modernSearchBar.searchImage = ModernSearchBarIcon.Icon.none.image

//Modify properties of the searchLabel
self.modernSearchBar.searchLabel_font = UIFont(name: "Avenir-Light", size: 30)
self.modernSearchBar.searchLabel_textColor = UIColor.red
self.modernSearchBar.searchLabel_backgroundColor = UIColor.black

//Modify properties of the searchIcon
self.modernSearchBar.suggestionsView_searchIcon_height = 40
self.modernSearchBar.suggestionsView_searchIcon_width = 40
self.modernSearchBar.suggestionsView_searchIcon_isRound = false

//Modify properties of suggestionsView
///Modify the max height of the suggestionsView
self.modernSearchBar.suggestionsView_maxHeight = 1000
///Modify properties of the suggestionsView
self.modernSearchBar.suggestionsView_backgroundColor = UIColor.brown
self.modernSearchBar.suggestionsView_contentViewColor = UIColor.yellow
self.modernSearchBar.suggestionsView_separatorStyle = .singleLine
self.modernSearchBar.suggestionsView_selectionStyle = UITableViewCellSelectionStyle.gray
self.modernSearchBar.suggestionsView_verticalSpaceWithSearchBar = 10
self.modernSearchBar.suggestionsView_spaceWithKeyboard = 20

Version

1.5

License

Copyright 2017 Boisney Philippe

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create New Pull Request

Author

Philippe BOISNEY (phil.boisney(@)gmail.com)

Comments
  • Better instalation section

    Better instalation section

    Hey, your library is really interesting.

    The only problem I found was the README.md, which has an incomplete Installation Section I created this iOS Open source Readme Template so you can take a look on how to easily create a complete Installation Section If you want, I can help you to organize the lib.

    What are your thoughts? 😄

    opened by lfarah 2
  • How to close suggestion when i selected one ?

    How to close suggestion when i selected one ?

    Hi,

    This project is perfect for me but I have a little problem..

    How to close suggestion list when i selected one ? When I click on suggestion, I have my data, I do my treatment but the suggestion bar is always displayed.

    Thx :)

    opened by ins0u 1
  • Can't customize searchBar

    Can't customize searchBar

    Hi the searchBar seems not assuming the custom values or anything but i don't have any error or warning. My code and storyboard: screen shot 2018-04-19 at 13 56 23

    My setup: class MyViewController: ModernSearchBarDelegate{ @IBOutlet weak var searchBar: ModernSearchBar!

       override func viewDidLoad() {
            super.viewDidLoad()
            self.searchBar.delegateModernSearchBar = self
            var suggestionList = Array<String>()
            suggestionList.append("Onions")
            suggestionList.append("Celery")
            
            self.searchBar.setDatas(datas: suggestionList)
            
            //Modify shadows alpha
            self.searchBar.shadowView_alpha = 0.8
            
            //Modify the default icon of suggestionsView's rows
            self.searchBar.searchImage = ModernSearchBarIcon.Icon.none.image
            
            //Modify properties of the searchLabel
            self.searchBar.searchLabel_font = UIFont(name: "Avenir-Light", size: 30)
            self.searchBar.searchLabel_textColor = UIColor.red
            self.searchBar.searchLabel_backgroundColor = UIColor.black
            
            //Modify properties of the searchIcon
            self.searchBar.suggestionsView_searchIcon_height = 40
            self.searchBar.suggestionsView_searchIcon_width = 40
            self.searchBar.suggestionsView_searchIcon_isRound = false
            
            //Modify properties of suggestionsView
            ///Modify the max height of the suggestionsView
            self.searchBar.suggestionsView_maxHeight = 1000
            ///Modify properties of the suggestionsView
            self.searchBar.suggestionsView_backgroundColor = UIColor.brown
            self.searchBar.suggestionsView_contentViewColor = UIColor.yellow
            self.searchBar.suggestionsView_separatorStyle = .singleLine
            self.searchBar.suggestionsView_selectionStyle = UITableViewCellSelectionStyle.gray
            self.searchBar.suggestionsView_verticalSpaceWithSearchBar = 10
            self.searchBar.suggestionsView_spaceWithKeyboard = 20
        }
    

    The result: screen shot 2018-04-19 at 14 01 59

    I can't figure out whats happening.

    Thanks in advance

    opened by firetrap 0
  • swift 4.2 update and important readme fix

    swift 4.2 update and important readme fix

    The swift 4.2 update was based on https://stackoverflow.com/questions/52466147/error-with-notification-names-while-converting-code-to-swift-4-2 and other Swift compiler recommendations.

    Please test one more time before merging.

    opened by ajRiverav 1
  • I propose fix to avoid null failure on iPhone 5

    I propose fix to avoid null failure on iPhone 5

    ##- OBS 1

    • When compiling the application and generating the error below in the ModernSearchBar.swift file in the updateSizeSuggestionsView () method updateSizeSuggestionsView()
    private func updateSizeSuggestionsView(){
        var frame: CGRect = self.suggestionsView.frame
        frame.size.height = self.getExactMaxHeightSuggestionsView(newHeight: self.suggestionsView.contentSize.height)
    
        UIView.animate(withDuration: 0.3) {
            self.suggestionsView.frame = frame
            self.suggestionsView.layoutIfNeeded()
            self.suggestionsView.sizeToFit()
        }
    }
    
    • Corrigir assim: (veja que foi adicionado um if para evitar objeto nulo)
    private func updateSizeSuggestionsView(){
        if(suggestionsView != nil){
            var frame: CGRect = self.suggestionsView.frame
            frame.size.height = self.getExactMaxHeightSuggestionsView(newHeight: self.suggestionsView.contentSize.height)
    
            UIView.animate(withDuration: 0.3) {
            self.suggestionsView.frame = frame
            self.suggestionsView.layoutIfNeeded()
            self.suggestionsView.sizeToFit()
            }
        }
    }
    

    ##- OBS 1

    • When compiling the application and generating the error below in the ModernSearchBar.swift file in the updateSizeSuggestionsView () method clearCacheOfList()
    private func clearCacheOfList(){
        ///Clearing cache
        for suggestionItem in self.suggestionListWithUrl {
            suggestionItem.imgCache = nil
        }
        ///Clearing cache
        for suggestionItem in self.suggestionListWithUrlFiltred {
            suggestionItem.imgCache = nil
        }
    
        self.suggestionsView.reloadData()
    }
    
    • Corrigir assim: (veja que foi adicionado um if para evitar objeto nulo)
    private func clearCacheOfList(){
        ///Clearing cache
        for suggestionItem in self.suggestionListWithUrl {
            suggestionItem.imgCache = nil
        }
        ///Clearing cache
        for suggestionItem in self.suggestionListWithUrlFiltred {
            suggestionItem.imgCache = nil
        }
    
        //Veja que foi adicionado um if para evitar objeto nulo
        if(suggestionsView != nil){
            self.suggestionsView.reloadData()
        }
    }
    
    opened by JeanBarreiros 0
  • Swift 4.2 errors

    Swift 4.2 errors

    There are many errors in Swift 4.2… Can you look at it? Thanks! Here are the errors:

    • UITableViewCellSeparatorStyle has been renamed to UITableViewCell.SeparatorStyle
    • UITableViewCellSelectionStyle has been renamed to UITableViewCell.SelectionStyle
    • UITableViewAutomaticDimension has been renamed to UITableView.automaticDimension
    • UIKeyboardWillShow has been renamed to UIResponder.keyboardWillShowNotification
    • UIKeyboardWillHide has been renamed to UIResponder.keyboardWillHideNotification
    • UIKeyboardFrameEndUserInfoKey has been renamed to UIResponder.keyboardFrameEndUserInfoKey
    • UIApplicationDidReceiveMemoryWarning has been renamed to UIApplication.didReceiveMemoryWarningNotification
    • UITableViewCellStyle has been renamed to UITableViewCell.CellStyle
    opened by flowbe 4
  • Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

    Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

    I have tried using this library - runs great on the emulator.

    Tried pushing it to the phone and I get this:

    Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

    This is inside the ModernSearchBarIcon.swift

    private func getImageFromBundle(name: String) -> UIImage { let podBundle = Bundle(for: ModernSearchBarIcon.self) if let url = podBundle.url(forResource: "ModernSearchBar", withExtension: "bundle") { let bundle = Bundle(url: url) return UIImage(named: name, in: bundle, compatibleWith: nil)! } return UIImage() }

    Gives out the error at "return UIImage(named: name, in: bundle, compatibleWith: nil)! "

    Any resolution??

    opened by snc001 1
Releases(1.5)
Owner
Boisney Philippe
Android Developer 📱🤖
Boisney Philippe
An auto growing text input bar for messaging apps.

ALTextInputBar An auto growing text input bar for messaging apps. Written in Swift. ALTextInputBar is designed to solve a few issues that folks usuall

Alex Littlejohn 265 Nov 15, 2022
A TextView that provides easy to use tagging feature for Mention or Hashtag

Tagging A TextView that provides easy to use tagging feature for Mention or Hashtag. Introduction Tagging is a UIView that encloses a TextView that co

DongHee Kang 109 Dec 5, 2022
iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more apps having maps.

MVAutocompletePlaceSearchTextField iOS - Subclass of UITextField to achieve autocompletion for Place Search like Google Places, Uber and Much more app

Mrugrajsinh Vansadia 68 May 27, 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
🔍 An elegant search controller which replaces the UISearchController for iOS (iPhone & iPad) .

?? 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

mamba 3.8k Jan 8, 2023
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
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
An UITextView in Swift. Support auto growing, placeholder and length limit.

GrowingTextView Requirements iOS 8.0 or above Installation CocoaPods GrowingTextView is available through CocoaPods. To install it, simply add the fol

Kenneth Tsang 941 Jan 5, 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
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
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
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

Eddy Borja 1.2k Nov 11, 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
📝 The next in the generations of 'growing textviews' optimized for iOS 8 and above.

NextGrowingTextView The next in the generations of 'growing textviews' optimized for iOS 8 and above. As a successor to HPGrowingTextView, NextGrowing

Muukii 1.7k Dec 25, 2022