Giter Club home page Giter Club logo

rsselectionmenu's Introduction

RSSelectionMenu

An elegant selection list or dropdown menu for iOS with single or multiple selections.

Alt text Alt text Alt text Alt text Alt text

Features

  • Show selection menu as list or popover with single or multiple selection.
  • Use different cell types. (Basic, RightDetail, SubTitle)
  • Works with Swift premitive types as well as custom NSObject classes.
  • Show selection menu with your custom cells.
  • Search from the list with inbuilt SearchBar.

Requirements

  • iOS 10.0+
  • Xcode 8.3+
  • Swift 3.0+

Installation

CocoaPods

pod 'RSSelectionMenu', '~> 1.0.4'
or
pod 'RSSelectionMenu', '~> 1.0.4', :git => 'https://github.com/rushisangani/RSSelectionMenu.git'

Usage

Simple Selection List

let simpleDataArray = ["Sachin", "Rahul", "Saurav", "Virat", "Suresh", "Ravindra", "Chris"]
var simpleSelectedArray = [String]()

let selectionMenu = RSSelectionMenu(dataSource: simpleDataArray, selectedItems:simpleSelectedArray) { (cell, object, indexPath) in
    cell.textLabel?.text = object
}
        
// title
selectionMenu.setNavigationBar(title: "Select Player")

selectionMenu.didSelectRow { (object, isSelected, selectedData) in
    
    // update existing array on select
    self.simpleSelectedArray = selectedData
}
selectionMenu.show(with: .push, from: self)

Present Modally with Right Detail and first row as None

let dataArray = ["Sachin Tendulkar", "Rahul Dravid", "Saurav Ganguli", "Virat Kohli", "Suresh Raina", "Ravindra Jadeja", "Chris Gyle", "Steve Smith", "Anil Kumble"]
var selectedDataArray = [String]()

let selectionMenu = RSSelectionMenu(dataSource: dataArray, selectedItems: selectedDataArray, cellType: .rightDetail) { (cell, object, indexPath) in
            
	let firstName = object.components(separatedBy: " ").first
	let lastName = object.components(separatedBy: " ").last

	cell.textLabel?.text = firstName
	cell.detailTextLabel?.text = lastName
}
        
// add first row as None
selectionMenu.showFirstRowAs(type: .None, selected: firstRowSelected) { (text, selected) in
    self.firstRowSelected = selected
}

selectionMenu.didSelectRow { (object, isSelected, selectedArray) in
    self.selectedDataArray = selectedArray
}

selectionMenu.show(from: self)

Multiple selection with search and custom Navigationbar theme

// set type as Multiple
let selectionMenu = RSSelectionMenu(selectionType: .multiple, dataSource: simpleDataArray, selectedItems: simpleSelectedArray) { (cell, object, indexPath) in
            
    cell.textLabel?.text = object
}
        
// set navigation title and color
selectionMenu.setNavigationBar(title: "Select Player", attributes: [NSForegroundColorAttributeName: UIColor.white], barTintColor: UIColor.orange.withAlphaComponent(0.5))


// add first row as All selected
selectionMenu.showFirstRowAs(type: .All, selected: firstRowSelected) { (text, selected) in
    self.firstRowSelected = selected
}

selectionMenu.didSelectRow { (object, isSelected, selectedData) in
    self.simpleSelectedArray = selectedData
}

// add searchbar
selectionMenu.addSearchBar { (searchText) -> ([String]) in

	// return filtered array based on your criteria
    return self.simpleDataArray.filter({ $0.lowercased().hasPrefix(searchText.lowercased()) })
}

selectionMenu.show(from: self)

Custom Cell with custom models or dictionary

class Person: NSObject {
    
    let id: Int
    let firstName: String
    let lastName: String

    init(id: Int, firstName: String, lastName: String) {
        self.id = id
        self.firstName = firstName
        self.lastName = lastName
    }
}

var customDataArray = [Person]()
var customselectedDataArray = [Person]()

// prepare data array with your custom models
customDataArray.append(Person(id: 1, firstName: "Sachin", lastName: "Tendulkar"))
customDataArray.append(Person(id: 2, firstName: "Rahul", lastName: "Dravid"))
customDataArray.append(Person(id: 3, firstName: "Virat", lastName: "Kohli"))


// specify unique key for your model or dictionary that contains an unique value.
// This is required to identify each row uniquely.

let selectionMenu = RSSelectionMenu(selectionType: .multiple, dataSource: customDataArray, selectedItems: customselectedDataArray, uniqueKey: "id") { (cell, person, indexPath) in
            
    let customCell = cell as! CustomTableViewCell
    customCell.setData(person: person)
}


// register your xib for tableviewcell        
selectionMenu.registerNib(nibName: "CustomTableViewCell", forCellReuseIdentifier: "cell")

selectionMenu.didSelectRow { (object, isSelected, selectedData) in
    self.customselectedDataArray = selectedData
}

selectionMenu.addSearchBar { (text) -> ([Person]) in
    return self.customDataArray.filter({ $0.firstName.lowercased().hasPrefix(text.lowercased()) })
}
selectionMenu.show(with: .push, from: self)

License

RSSelectionMenu is released under the MIT license. See LICENSE for details.

rsselectionmenu's People

Contributors

rushisangani avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.