Tell me please, How I can set minimum and maximum date and just date for UIDatePicker with RxSwift
Asked
Active
Viewed 530 times
0
-
I suggest you improve questions by giving more details...rather than sharing using comments. – Shahriar Hossain Nov 18 '21 at 14:18
-
1You surely tried _something_. SO is not a free code writing website. Without showing at least some (research) effort, you're highly unlikely to receive an answer here. – Dávid Pásztor Nov 18 '21 at 14:39
-
Do you want these dates to dynamically change? If not, then there's no call to use RxSwift to do it... If so, then tell us more about the requirements so we can help. – Daniel T. Nov 18 '21 at 23:47
2 Answers
0
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

Shahriar Hossain
- 119
- 2
- 13
0
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
.

Daniel T.
- 32,821
- 6
- 50
- 72
-
How do you set date in `fromPicker.rx.date` , I have to set start date in my `datePicker`, I can do it like `datePicker.Date = date`, but I wont set this value with Rx – Valerii Vvedenskyi Nov 19 '21 at 10:05
-