UIalertController date control, uialertcontroller
The idea is that the height of the UIalertController is determined by the content, and the view can be modified.
First, you do not need to change the class initialization (because you only need to modify the view Interface)
Inherit the. h file of UIalertController
#import <UIKit/UIKit.h>typedef void(^BlockDate)(id date);@interface SheetDate : UIAlertController@property(nonatomic,copy)BlockDate blockDate;@property(retain,nonatomic)UIDatePicker* datePicker;-(NSString*)dealDate;-(void)addDatePicker;@end
Inherit from the. m file of UIalertController
# Import "SheetDate. h "@ interface SheetDate () @ end @ implementation SheetDate-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view from its nib .} -(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} /*** add date control */-(void) addDatePicker {self. datePicker = [[UIDatePicker alloc] initWithFrame: CGRectMake (0, 0,320,216)]; self. datePicker. datePickerMode = UIDatePickerModeDate; self. datePicker. locale = [[NSLocale alloc] initWithLocaleIdentifier: @ "zh_CN"]; [self. view addSubview: self. datePicker];}/*** process date data ** @ return */-(NSString *) dealDate {NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; if (self. datePicker. datePickerMode = UIDatePickerModeTime) {[formatter setDateFormat: @ "HH: ss"];} else {[formatter setDateFormat: @ "YYYY-MM-dd"];} NSString * currentTime = [formatter stringFromDate: self. datePicker. date]; return currentTime ;}
Then use
/*** Date/time select ** @ param sender */-(IBAction) chooseDate :( UIButton *) sender {SheetDate * sheetDate = [SheetDate alertControllerWithTitle: nil message: @ "\ n" preferredStyle :( UIAlertControllerStyleActionSheet)]; [sheetDate addDatePicker]; sheetDate. blockDate = ^ (NSString * date) {[sender setTitle: date forState :( UIControlStateNormal)] ;}; // start time, end time if (sender. tag = 70 | sender. tag = 71) {sheetDate. datePicker. datePickerMode = idle;} UIAlertAction * OK = [UIAlertAction actionWithTitle: @ "OK" style :( UIAlertActionStyleDefault) handler: ^ (UIAlertAction * _ nonnull action) {sheetDate. blockDate ([sheetDate dealDate]);}]; [sheetDate addAction: OK]; [self presentViewController: sheetDate animated: YES completion: nil];
First, create a uialertcontroller object using the system method. Use \ n to increase the display height. Then call [sheetDate addDatePicker] to add a custom interface and initialize the block using date data as needed.
Then, trigger it in the sheet option.