Giter Site home page Giter Site logo

mostafataghipour / mtppickerfield Goto Github PK

View Code? Open in Web Editor NEW
18.0 5.0 2.0 2.51 MB

UITextField + ActionSheet + (UIPickerView, UIDatePicker, UITableView, UICollectionView)

License: MIT License

Ruby 7.10% Swift 92.90%
uidatepicker uipickerview actionsheet uicollectionview uitableview

mtppickerfield's Introduction

mtpPickerField

CI Status Version License Platform

mtpPickerField is a good component to choose from among several options. This custom control is made up of a UITextField combination one of the UIPickerView, UIDatePicker, UItableView, UICollectionView controls that are built into a ActionSheet

screen shots

Requirements

  • iOS 9.0+
  • Xcode 9+

Installation

mtpPickerField is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'mtpPickerField'

Usage

  • Drag a UITextView object onto the canvas.
  • In the Identity inspector, set the Custom Class name to PickerField
  • Set its type
  • Now You can use the control according to the type of field
class ViewController: UIViewController , UIPickerViewDataSource {
    @IBOutlet weak var pickerViewField: PickerField!
    let states = ["Alaska",
                "Alabama",
                "Arkansas",
                "American Samoa",
                "Arizona",
                "California"]

    override func viewDidLoad() {
        super.viewDidLoad()

        pickerViewField.type = .pickerView
        pickerViewField.pickerView?.dataSource=self
        pickerViewField.placeholder="your state ..."
        pickerViewField.titleLabel?.text="select a state"
        pickerViewField.pickerFieldDelegate=self
        tabelViewField.height=400
        tabelViewField.cancelWhenTouchUpOutside=false
    }

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return states.count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return states[row]
    }

}
  • Also you can use PickerFieldDelegate aware of occurrence of events
extension ViewController:PickerFieldDelegate{
    func pickerField(didOKClick pickerField: PickerField) {
        if pickerField.type == .pickerView{
            if let row=pickerField.pickerView?.selectedRow(inComponent: 0){
                pickerField.text=states[row]
            }
        }
    }
}

For more exmples please review example project

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Author

Mostafa Taghipour, [email protected]

License

mtpPickerField is available under the MIT license. See the LICENSE file for more info.

mtppickerfield's People

Contributors

mostafataghipour avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.