Home > Software engineering >  How to realize UIDatePicker with RXSwift
How to realize UIDatePicker with RXSwift

Time:11-19

Tell me please, How I can set minimum and maximum date and just date for UIDatePicker with RxSwift

CodePudding user response:

You probably want something like this. Swift 4:

let calendar = Calendar(identifier: .gregorian)
var comps = DateComponents()
comps.year = 30
let maxDate = calendar.date(byAdding: comps, to: Date())
comps.year = -30
let minDate = calendar.date(byAdding: comps, to: Date())
datePicker.maximumDate = maxDate
datePicker.minimumDate = minDate

CodePudding user response:

It's hard to answer this question without knowing more. I'll post some code from one of my projects:

fromPicker.rx.date
    .bind(to: toPicker.rx.minimumDate)
    .disposed(by: disposeBag)

The idea with the above code is to implement a feature that ensures that the user can't set the toPicker to a date earlier than what they set the fromPicker.

  • Related