Skip to content

Commit

Permalink
Add datePicker style property to XLFormDateCell (#1078)
Browse files Browse the repository at this point in the history
Co-authored-by: Nick <[email protected]>
  • Loading branch information
nickreffitt and Nick authored Nov 18, 2020
1 parent 74bde21 commit ded97b8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions XLForm/XL/XLFormDateCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions XLForm/XL/XLFormDateCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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]];
}
Expand Down Expand Up @@ -225,13 +227,34 @@ -(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
{
if (_datePicker) return _datePicker;
_datePicker = [[UIDatePicker alloc] init];
[self setModeToDatePicker:_datePicker];
[self setStyleToDatePicker:_datePicker];
[_datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
return _datePicker;
}
Expand Down Expand Up @@ -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];
}
}
}
Expand Down

0 comments on commit ded97b8

Please sign in to comment.