Latest 1.0.8
Homepage https://github.com/sag333ar/InputViews
License MIT
Platforms ios 10.0
Authors

InputViews Title

Example1 Example2 Example3
DatePicker ItemPicker ItemsPicker
Example4 Example5 Example6
ItemsPicker IconPicker ColorPicker

Input views for UITextField show PickerView, TableView, Collection, instead of default keyboard

Pod
Platform
License

It helps you convert ordinary UITextfield to item picker of multiple style.

Features

  • [x] Date Picker (Example1)
  • [x] Item Picker using UIPickerView (Example2)
  • [x] Item Picker using UITableView (Example3)
  • [x] Item Picker using UICollectionView (Example4)
  • [x] Quick AccessoryView with done button (All examples with done button toolbar)
  • [x] Font Awesome Icon Picker (Example5)
  • [x] UIColor Picker (Example6)

Requirements

  • iOS 10.0+
  • Xcode 10.2.1+

Installation

CocoaPods

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

platform :ios, '10.0'
use_frameworks!
pod 'InputViews'

To get the full benefits import InputViews wherever you import UIKit

import UIKit
import InputViews

Usage Guide

Date Picker (Example1)

@IBOutlet var datePicker: NoCutPasteTextField? {
  didSet {
    guard let datePicker = datePicker else { return }
    // Setting up input view
    datePicker.inputView = DatePickerInputView(
      mode: .dateAndTime, didSelect: { (date) in
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "dd-MMM-yyyy hh:mm a"
        datePicker.text = dateFormatter.string(from: date)
    })
    // Setting up accessory view
    datePicker.inputAccessoryView = AccessoryView("Select Date", doneTapped: {
      datePicker.resignFirstResponder()
    })
  }
}

Item picker with UIPickerView (Example2)

@IBOutlet var itemPicker: NoCutPasteTextField? {
  didSet {
    guard let itemPicker = itemPicker else { return }
    let array = ["First item", "Second item", "Third item", "Fourth item", "Fifth", "and sixth"]
    // Setting up input view
    let inputView = PickerInputView<String>(height: 250)
    inputView.items = { return array }
    inputView.didSelectAtIndex = { index in itemPicker.text = array[index] }
    inputView.text = { string in return string }
    itemPicker.inputView = inputView
    // Setting up accessory view
    itemPicker.inputAccessoryView = AccessoryView("Select item", doneTapped: {
      itemPicker.resignFirstResponder()
    })
  }
}

Items picker with UITableView (Example3)

@IBOutlet var itemsFromTablePicker: NoCutPasteTextField? {
  didSet {
    guard let itemsFromTablePicker = itemsFromTablePicker else { return }
    let array = ["First item", "Second item", "Third item", "Fourth item", "Fifth", "and sixth"]
    var selected: [String] = []
    let inputView = TableInputView<String>.init(height: 250)
    inputView.items = { return array }
    inputView.didSelect = { string in
      if let index = selected.firstIndex(of: string) {
        selected.remove(at: index)
      } else {
        selected.append(string)
      }
      itemsFromTablePicker.text = selected.joined(separator: ", ")
    }
    inputView.contains = { string in return selected.firstIndex(of: string) != nil }
    inputView.text = { string in return string }
    itemsFromTablePicker.inputView = inputView
    // Setting up accessory view
    itemsFromTablePicker.inputAccessoryView = AccessoryView("Select item", doneTapped: {
      itemsFromTablePicker.resignFirstResponder()
    })
  }
}

Items picker with UICollectionView (Example4)

@IBOutlet var itemsFromCollectionView: NoCutPasteTextField? {
  didSet {
    guard let itemsFromCollectionView = itemsFromCollectionView else { return }
    let array = ["First item", "Second item", "Third item", "Fourth item", "Fifth", "and sixth"]
    var selected: [String] = []
    let inputView = CollectionInputView<String>(height: 250)
    inputView.items = { return array }
    inputView.didSelect = { string in
      if let index = selected.firstIndex(of: string) {
        selected.remove(at: index)
      } else {
        selected.append(string)
      }
      itemsFromCollectionView.text = selected.joined(separator: ", ")
    }
    inputView.text = { string in return string }
    inputView.contains = { string in return selected.firstIndex(of: string) != nil }
    itemsFromCollectionView.inputView = inputView
    // Setting up accessory view
    itemsFromCollectionView.inputAccessoryView = AccessoryView("Select item", doneTapped: {
      itemsFromCollectionView.resignFirstResponder()
    })
  }
}

Pick Font Awesome Icon (Example5)

@IBOutlet var pickFontAwesomeIconView: NoCutPasteTextField? {
  didSet {
    guard let pickFontAwesomeIconView = pickFontAwesomeIconView else { return }
    pickFontAwesomeIconView.inputView = PickFontAwesomeIconView(didSelect: { (icon) in
      print("Icon is (icon)")
    }, height: 250)
    // Setting up accessory view
    pickFontAwesomeIconView.inputAccessoryView = AccessoryView("Select item", doneTapped: {
      pickFontAwesomeIconView.resignFirstResponder()
    })
  }
}

Pick UIColor (Example6)

@IBOutlet var colorPicker: NoCutPasteTextField? {
  didSet {
    guard let colorPicker = colorPicker else { return }
    var selectedColor: UIColor?
    colorPicker.inputView = ColorPickerView.init(didSelect: { (color) in
      colorPicker.backgroundColor = color
      selectedColor = color
    }, contains: { (color) in
      return color.isEqual(selectedColor)
    }, height: 250, colorSize: 30)
    // Setting up accessory view
    colorPicker.inputAccessoryView = AccessoryView("Select Color", doneTapped: {
      colorPicker.resignFirstResponder()
    })
  }
}

Latest podspec

{
    "name": "InputViews",
    "version": "1.0.8",
    "summary": "Custom input views for UIKeyboard",
    "description": "Input views for UITextField show PickerView, TableView, Collection, instead of default keyboard",
    "homepage": "https://github.com/sag333ar/InputViews",
    "license": "MIT",
    "authors": {
        "Sagar Kothari": "sag3[email protected]"
    },
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/sag333ar/InputViews.git",
        "tag": "1.0.8"
    },
    "swift_versions": "5.0",
    "swift_version": "5.0",
    "subspecs": [
        {
            "name": "AccessoryView",
            "source_files": "InputViews/AccessoryView/**/*.{swift}"
        },
        {
            "name": "CollectionInputView",
            "source_files": "InputViews/CollectionInputView/*.{swift}",
            "subspecs": [
                {
                    "name": "PickFontAwesomeIconView",
                    "resources": "InputViews/CollectionInputView/PickFontAwesomeIconView/*.{otf}",
                    "source_files": "InputViews/CollectionInputView/**/*.{swift}"
                }
            ]
        },
        {
            "name": "DatePickerInputView",
            "source_files": "InputViews/DatePickerInputView/**/*.{swift}"
        },
        {
            "name": "ColorPickerView",
            "source_files": [
                "InputViews/ColorPickerView/**/*.{swift}",
                "InputViews/CollectionInputView/CollectionInputViewCell.swift"
            ]
        },
        {
            "name": "NoCutPasteField",
            "source_files": "InputViews/NoCutPasteField/**/*.{swift}"
        },
        {
            "name": "PickerInputView",
            "source_files": "InputViews/PickerInputView/**/*.{swift}"
        },
        {
            "name": "TableInputView",
            "source_files": "InputViews/TableInputView/**/*.{swift}"
        }
    ]
}

Pin It on Pinterest

Share This