选择器 - 日期选择,内容选择

https://github.com/skywinder/ActionSheetPicker-3.0

日期选择

    [ActionSheetDatePicker showPickerWithTitle:@"标题"
                                datePickerMode:UIDatePickerModeDate
                                  selectedDate:[NSDate date]
                                   minimumDate:[NSDate dateWithTimeIntervalSinceNow:-30 * 24 * 3600]
                                   maximumDate:[NSDate dateWithTimeIntervalSinceNow:30 * 24 * 3600]
                                     doneBlock:^(ActionSheetDatePicker *picker, id selectedDate, id origin) {
                                         
                                         NSLog(@"%@",selectedDate);
                                         
                                     } cancelBlock:^(ActionSheetDatePicker *picker) {
                                         NSLog(@"cancel");
                                         
                                     } origin:self.view];

内容选择

    [ActionSheetStringPicker showPickerWithTitle:@"title"
                                            rows:@[@"0",@"1",@"2",@"3",@"4"]
                                initialSelection:2
                                       doneBlock:^(ActionSheetStringPicker *picker, NSInteger selectedIndex, id selectedValue) {
                                           
                                           NSLog(@"%ld - %@",(long)selectedIndex, selectedValue);
                                           
                                       } cancelBlock:^(ActionSheetStringPicker *picker) {
                                           
                                           NSLog(@"cancel");
                                           
                                       } origin:self.view];

多重选择

    NSArray *section1 = @[@"0",@"1",@"2",@"3",@"4"];
    NSArray *section2 = @[@"0",@"1",@"2",@"3",@"4"];

    NSArray *sectionData = @[section1,section2];
    NSArray *selectIndex = @[@1,@2];
    
[ActionSheetMultipleStringPicker showPickerWithTitle:@"title"
                                                rows:sectionData
                                    initialSelection:selectIndex
                                           doneBlock:^(ActionSheetMultipleStringPicker *picker, NSArray *selectedIndexes, id selectedValues) {
                                               
                                               NSLog(@"%@",selectedValues);// 也是 数组,对应section1,section2 ...
                                               
                                           } cancelBlock:^(ActionSheetMultipleStringPicker *picker) {
                                               
                                           } origin:self.view];

时区选择

[ActionSheetLocalePicker showPickerWithTitle:@"title"
                            initialSelection:[NSTimeZone defaultTimeZone]
                                   doneBlock:^(ActionSheetLocalePicker *picker, NSTimeZone *selectedValue) {
                                       
                                       NSLog(@"%@",selectedValue);
                                       
                                   } cancelBlock:^(ActionSheetLocalePicker *picker) {
                                       
                                   } origin:self.view];

自定义

如果要自定义的话,其实就是直接写一个PickView 代理。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    
    [ActionSheetCustomPicker showPickerWithTitle:@"title"
                                        delegate:self
                                showCancelButton:YES
                                          origin:self.view];
}

#pragma mark - ActionSheetCustomPicker Delegate

- (void)actionSheetPicker:(AbstractActionSheetPicker *)actionSheetPicker configurePickerView:(UIPickerView *)pickerView {
    pickerView.delegate = self;
}

- (void)actionSheetPickerDidSucceed:(AbstractActionSheetPicker *)actionSheetPicker origin:(id)origin {
    NSLog(@"success");
}

- (void)actionSheetPickerDidCancel:(AbstractActionSheetPicker *)actionSheetPicker origin:(id)origin {
    NSLog(@"cancel");
}

#pragma mark - PickView Delegete

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 2;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return 10;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return @"ertyhjk";// 举例而已
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    NSLog(@"%ld - %ld",component, row);
}

1

你可能感兴趣的:(选择器 - 日期选择,内容选择)