coolly coolly - 6 months ago 110
iOS Question

How to create and subclass custom UIPickerView which shows only date, in swift?

In swift, how to create custom picker view by subclass UPickerView, so it shows only date picker? Couldn't find answer for this. Any kind of help is appreciated.

Answer

to be able to instantiate the picker from code AND storyboard you have to override both initializers like this:

class DatePicker: UIDatePicker {
    override init(frame: CGRect) {
        super.init(frame: frame)
        sharedInit()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        sharedInit()
    }

    private func sharedInit() {
        datePickerMode = .Date
    }
}