美文网首页
iOS 选择器和日期选择器

iOS 选择器和日期选择器

作者: YannChee | 来源:发表于2017-05-25 18:26 被阅读188次

    效果图:


    使用方法:

    • 1.调用工厂方法创建,设置frame
    • 2.设置数据源数组
    • 3.设置选择确定的block
    - (IBAction)btn1Click:(UIButton *)sender {
        QYRegionPickerView *pickerV = [QYRegionPickerView regionView];
        pickerV.frame = [UIScreen mainScreen].bounds;
        NSArray *pickerSourceArr = @[@"乌鲁木齐",@"昌吉"]; // 0是乌鲁木齐市 1是昌吉
        pickerV.pickerSourceArr = pickerSourceArr;
        pickerV.pickSuccessBlock = ^(NSInteger arrIndex) {
            NSString* str = pickerSourceArr[arrIndex];
            [sender setTitle:str forState:UIControlStateNormal];
        };
        
        [self.view addSubview:pickerV];
    }
    

    日期选择器:

    - (IBAction)btn2Click:(UIButton *)sender {
        QYDatePickerView *pickerV = [QYDatePickerView datePickerView];
        pickerV.frame = [UIScreen mainScreen].bounds;
        pickerV.pickDateSuccessBlock = ^(NSString *dateStr) {
            [sender setTitle:dateStr forState:UIControlStateNormal];
        };
        
        [self.view addSubview:pickerV];
    }
    

    源码地址https://github.com/YannChee/QYPicker

    重大更新:

    我已将上面的view 封装到一个控制器中,一句代码搞定选择器, 有时间会更新到github

    .文件

    #import <UIKit/UIKit.h>
    
    @interface QYNormalPickerController : UIViewController
    
    + (instancetype)pickerViewControllerWithSourceArr:(NSArray *)pickerSourceArr pickConfirmBlock:(void (^)(NSInteger selectedIndex)) PickConfirmBlock;
    @end
    

    使用方法

    - (IBAction)jobKindBtnClick:(id)sender {
         NSArray *pickerSourceArr = @[@"乌鲁木齐",@"昌吉",@"哈哈"]; // 0是乌鲁木齐市 1是昌吉 3哈哈
    
        QYNormalPickerController *normalPickerVC = [QYNormalPickerController pickerViewControllerWithSourceArr:pickerSourceArr pickConfirmBlock:^void (NSInteger selectedIndex) {
            NSString* str = pickerSourceArr[selectedIndex];
            [sender setTitle:str forState:UIControlStateNormal];
     
        }];
    
        [self presentViewController:normalPickerVC animated:YES completion:nil];
    }
    

    相关文章

      网友评论

          本文标题:iOS 选择器和日期选择器

          本文链接:https://www.haomeiwen.com/subject/xnraxxtx.html