Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add formDatePickerStyle property to XLFormDateCell #1078

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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