Reputation: 961
Is there way to remove only minutes from UIDatePickerMode
? I tried to search many posts and i still haven't find.
I see Date, Time , Date and Time, Count Down Timer from DatePicker
Menu
The following image is got by choosing Date and Time.
But I need to do is like following image.
Any ideas, tips? Thank you!
Upvotes: 3
Views: 1268
Reputation: 729
As Christian mentioned, you can't edit the UIDatePicker
. What you can do is use a UIPickerView
. Implement the dataSource
to return 3 components
, 1 for each column. Then have an array for the possible options for month
, day
and hour time
.
dataSource:
let monthsArray = ["august"..]
var daysArray = [1..31] //include logic for actual days of the month
let hoursArray = ["1pm"..]
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 3
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
switch component {
case 1: return monthsArray.count
case 2: return daysArray.count
case 3: return hoursArray.count
}
}
you also need to implement the delegate for knowing what the user has selected
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
Upvotes: 2