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

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<UITouch *> *)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

推薦閱讀更多精彩內容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017閱讀 70,492評論 12 116
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim閱讀 124,495評論 16 534
  • 太长了,还是转载吧...今天在看博客的时候,无意中发现了@Trinea在GitHub上的一个项目Android开源...
    庞哈哈哈12138閱讀 16,335評論 5 281
  • Yolanda来自西班牙语,是紫罗兰的意思。 希腊神话里,主管爱与美的女神维纳斯,因情人远行,依依惜别,晶莹的泪珠...
    悠然Yolanda閱讀 434評論 0 0
  • 一次思想上的碰撞,一次快乐的出发,樊登读书会,全民读书,人人幸福。 重新定义公司 中的① 赋能 把权利赋予给员工,...
    马硕我的男神閱讀 42評論 0 0