From ded97b83284e27eca33a8440dcf57e0f8645e57f Mon Sep 17 00:00:00 2001 From: Nick Reffitt Date: Wed, 18 Nov 2020 13:00:10 +0000 Subject: [PATCH] Add datePicker style property to XLFormDateCell (#1078) Co-authored-by: Nick --- XLForm/XL/XLFormDateCell.h | 8 ++++++++ XLForm/XL/XLFormDateCell.m | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/XLForm/XL/XLFormDateCell.h b/XLForm/XL/XLFormDateCell.h index da53e81d..aada45c6 100644 --- a/XLForm/XL/XLFormDateCell.h +++ b/XLForm/XL/XLFormDateCell.h @@ -32,9 +32,17 @@ typedef NS_ENUM(NSUInteger, XLFormDateDatePickerMode) { XLFormDateDatePickerModeTime }; +typedef NS_ENUM(NSUInteger, XLFormDateDatePickerStyle) { + XLFormDateDatePickerStyleAutomatic, + XLFormDateDatePickerStyleCompact, + XLFormDateDatePickerStyleInline, + XLFormDateDatePickerStyleWheels +}; + @interface XLFormDateCell : XLFormBaseCell @property (nonatomic, assign) XLFormDateDatePickerMode formDatePickerMode; +@property (nonatomic, assign) XLFormDateDatePickerStyle formDatePickerStyle; @property (nonatomic, copy ) NSDate *minimumDate; @property (nonatomic, copy ) NSDate *maximumDate; @property (nonatomic, assign) NSInteger minuteInterval; diff --git a/XLForm/XL/XLFormDateCell.m b/XLForm/XL/XLFormDateCell.m index 5821fcd7..2b7384ed 100644 --- a/XLForm/XL/XLFormDateCell.m +++ b/XLForm/XL/XLFormDateCell.m @@ -48,6 +48,7 @@ - (UIView *)inputView [self.datePicker setDate:self.rowDescriptor.value animated:[self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeCountDownTimer]]; } [self setModeToDatePicker:self.datePicker]; + [self setStyleToDatePicker:self.datePicker]; return self.datePicker; } return [super inputView]; @@ -74,6 +75,7 @@ -(BOOL)becomeFirstResponder XLFormRowDescriptor * datePickerRowDescriptor = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:XLFormRowDescriptorTypeDatePicker]; XLFormDatePickerCell * datePickerCell = (XLFormDatePickerCell *)[datePickerRowDescriptor cellForFormController:self.formViewController]; [self setModeToDatePicker:datePickerCell.datePicker]; + [self setStyleToDatePicker:datePickerCell.datePicker]; if (self.rowDescriptor.value){ [datePickerCell.datePicker setDate:self.rowDescriptor.value animated:[self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeCountDownTimerInline]]; } @@ -225,6 +227,26 @@ -(void)setModeToDatePicker:(UIDatePicker *)datePicker } } +-(void)setStyleToDatePicker:(UIDatePicker *)datePicker +{ + if (@available(iOS 14.0, *)) { + switch (self.formDatePickerStyle) { + case XLFormDateDatePickerStyleInline: + datePicker.preferredDatePickerStyle = UIDatePickerStyleInline; + break; + case XLFormDateDatePickerStyleCompact: + datePicker.preferredDatePickerStyle = UIDatePickerStyleCompact; + break; + case XLFormDateDatePickerStyleWheels: + datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels; + break; + default: + datePicker.preferredDatePickerStyle = UIDatePickerStyleAutomatic; + break; + } + } +} + #pragma mark - Properties -(UIDatePicker *)datePicker @@ -232,6 +254,7 @@ -(UIDatePicker *)datePicker if (_datePicker) return _datePicker; _datePicker = [[UIDatePicker alloc] init]; [self setModeToDatePicker:_datePicker]; + [self setStyleToDatePicker:_datePicker]; [_datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged]; return _datePicker; } @@ -262,6 +285,7 @@ -(void)setFormDatePickerMode:(XLFormDateDatePickerMode)formDatePickerMode if ([nextFormRow.rowType isEqualToString:XLFormRowDescriptorTypeDatePicker]){ XLFormDatePickerCell * datePickerCell = (XLFormDatePickerCell *)[nextFormRow cellForFormController:self.formViewController]; [self setModeToDatePicker:datePickerCell.datePicker]; + [self setStyleToDatePicker:datePickerCell.datePicker]; } } }