Search code examples
iosobjective-cuidatepicker

Allow Week days in Date Picker in Obj C


I am using ActionSheetDatePicker, I can select four datePickerMode i.e.

typedef NS_ENUM(NSInteger, UIDatePickerMode) {
    UIDatePickerModeTime,           // Displays hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. 6 | 53 | PM)
    UIDatePickerModeDate,           // Displays month, day, and year depending on the locale setting (e.g. November | 15 | 2007)
    UIDatePickerModeDateAndTime,    // Displays date, hour, minute, and optionally AM/PM designation depending on the locale setting (e.g. Wed Nov 15 | 6 | 53 | PM)
    UIDatePickerModeCountDownTimer, // Displays hour and minute (e.g. 1 | 53)
} __TVOS_PROHIBITED;

There is no option to display week days in Picker, Can somebody help me, how can I display week days including date, month and year, excluding time in date picker.

I am working in obj C.

Thanks!


Solution

  • you need to modify your datasource. you need three things day, date,month and year. You can use NSDateComponents to separate date into these components, and once your month increases or decreases, you need to modify data source again.

    ActionSheetStringPicker showPickerWithTitle:@"Select Date"
                                        rows://add your data source here
                            initialSelection:0
                                   doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
                                      NSLog(@"Picker: %@, Index: %@, value: %@", 
                                      picker, selectedIndex, selectedValue);
                                    }
                                 cancelBlock:^(ActionSheetStringPicker *picker) {
                                      NSLog(@"Block Picker Canceled");
                                    }
                                      origin:sender];
    

    Hope this helps :)