Swiftpack.co - Aiur3908/AYPopupPickerView as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Aiur3908.
Aiur3908/AYPopupPickerView 1.2
A Popup PickerView or DatePickerView
⭐️ 22
🕓 3 years ago
iOS
.package(url: "https://github.com/Aiur3908/AYPopupPickerView.git", from: "1.2")

AYPopupPickerView

A Popup PickerView or DatePickerView

Swift 5 CocoaPods Compatible Carthage compatible SPM Platform License

image

Installation

CocoaPods

pod 'AYPopupPickerView'

Carthage

github "Aiur3908/AYPopupPickerView"

Swift Package Manager

File -> Swift Packages -> Add Package Dependency

https://github.com/Aiur3908/AYPopupPickerView

Manually

Drag and drop source folder to your project.

Usage

AYPopupPickerView

let itemsTitle = ["Apple", "Avocado", "Banana", "Cherry", "Coconut", "Grape"]
let popupPickerView = AYPopupPickerView()
popupPickerView.display(itemTitles: itemsTitle, doneHandler: {
    let selectedIndex = popupPickerView.pickerView.selectedRow(inComponent: 0)
    print(itemsTitle[selectedIndex])
})

AYPopupDatePickerView

let popupDatePickerView = AYPopupDatePickerView()
popupDatePickerView.display(defaultDate: Date(), doneHandler: { date in
    print(date)
})

Custom Implementation

AYPopupPickerView

public var pickerView: UIPickerView!
public var doneButton: UIButton!
public var cancelButton: UIButton!
public var headerView: UIView!

AYPopupDatePickerView

public var datePickerView: UIDatePicker!
public var doneButton: UIButton!
public var cancelButton: UIButton!
public var headerView: UIView!

Example

let customPopupPickerView = AYPopupPickerView()
customPopupPickerView.headerView.backgroundColor = UIColor.green
customPopupPickerView.doneButton.setTitle("OK", for: .normal)
customPopupPickerView.doneButton.setTitleColor(.red, for: .normal)
customPopupPickerView.cancelButton.setTitleColor(.blue, for: .normal)
let customPopupDatePickerView = AYPopupDatePickerView()
customPopupDatePickerView.datePickerView.datePickerMode = .date

Multiple Component

You can implementation UIPickerViewDataSource & UIPickerViewDelegate in your ViewController

class ViewController: UIViewController {
    
    let popupPickerView = AYPopupPickerView()

    override func viewDidLoad() {
        super.viewDidLoad()
        popupPickerView.pickerView.dataSource = self
        popupPickerView.pickerView.delegate = self
    }

    @IBAction func display(_ sender: Any) {
        popupPickerView.display(doneHandler: {
            
        })
    }
}

extension ViewController: UIPickerViewDataSource & UIPickerViewDelegate {
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 2
    }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return 5
    }
    
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return "\(row)"
    }
}

To set a default item selected

Single Component

popupPickerView.display(itemTitles: itemsTitle, defaultIndex: 1, doneHandler: {

})

Multiple Component

//defaultSelects: [(row: Int, component: Int)]
popupPickerView.display(with: [(2,0), (1,1)], doneHandler: {

})

Author

Jerry You Email: [email protected]

Contributing

Pull requests, feature requests and bug reports are welcome 🚀

LICENSE

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

GitHub

link
Stars: 22
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics