Skip to content

Modern String Picker or dropdown menu for iOS with search functionality.

License

Notifications You must be signed in to change notification settings

didats/DTStringPicker

Repository files navigation

DTStringPicker

GitHub release Swift 5.0 Version License Platform CocoaPods

A modern String Picker with search functionality. You are able to set the text alignment, background color, text color, font as well.

Behind the scene

To let user choose an option in iOS you may choose a default UI which called UIPickerView. But configuring the UIPickerView with a good approach is not that easy. Few years back, I have found that ActionSheetPicker is useful. That library is combining UIActionSheet and UIPickerView.

But this is 2021. In my opinion, we should have better choice. After no longer using ActionSheetPicker, I made a list of options in another page with UITableView. Then instead of going to other page, I made DTStringPicker.

Hopefully, it will benefit many developer out there searching for ActionSheetPicker alternative.

Features

This library is very useful atleast for me, for these kind of situations:

  1. You need to let your user choose more than 2 options
  2. You want to show the option with sections
  3. You want to let user search for an option
  4. You want to something modern

Screenshot

Requirements

  • Base SDK: iOS 12
  • Deployment Target: iOS 12.0 or greater

Installation

Add following in your Podfile.

pod 'DTStringPicker', :git => 'https://github.com/didats/DTStringPicker'

Usage without section

// specify the strings
let rows = ["Number 1", "Another option 2", "The third choice", "4th item", "Other option", "Anything option"]

// create configuration
var config = DTStringPickerConfig(color: UIColor.black, background: UIColor.white)
config.title = "Choose one option"
config.alignment = .right

DTStringPicker.show(with: config, rowItems: rows.map({ DTStringPickerModelItem(text: $0) }), done: { item in
	print("Item: \(item)")
}, cancel: {
	print("Cancel ===")
}, from: self)

Usage with section and complete configuration

// specify the strings
let rows: [DTStringPickerModelSection] = [
	DTStringPickerModelSection(
		title: "Header 1",
		items: [
			DTStringPickerModelItem(text: "Pilih satu dua"),
			DTStringPickerModelItem(text: "Ini nomor dua"),
			DTStringPickerModelItem(text: "Di sini nomor ketiga"),
		]),
	DTStringPickerModelSection(
		title: "Second Header",
		items: [
			DTStringPickerModelItem(text: "Pilih satu dua"),
			DTStringPickerModelItem(text: "Ini nomor dua"),
			DTStringPickerModelItem(text: "Di sini nomor ketiga"),
		]),
]

// custom ui
var config = DTStringPickerConfig(color: UIColor.black, background: UIColor.white)
config.title = "Choose one option"
config.alignment = .left
config.itemFont = UIFont.systemFont(ofSize: 17, weight: .regular)
config.color = UIColor.black
config.backgroundColor = UIColor.white
config.shadowColor = UIColor.black
config.titleFont = UIFont.systemFont(ofSize: 30, weight: .bold)
config.titleColor = UIColor.black
config.sectionBackground = UIColor.init(red: 240/255, green: 240/255, blue: 240/255, alpha: 1)
config.sectionFont = UIFont.systemFont(ofSize: 16, weight: .bold)
config.sectionColor = UIColor.black

DTStringPicker.show(with: config, rowSections: rows, done: { item in
	print("Item: \(item)")
}, cancel: {
	print("Cancel ===")
}, from: self)

Author

Didats Triadi
http://rimbunesia.com
http://didatstriadi.com

License

Copyright (c) 2019 Didats Triadi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.