时间选择器(UIDatePicker)和自定义选择器(UIPickView)

本文介绍了如何在iOS应用中使用时间选择器(UIDatePicker)以及如何自定义选择器(UIPickerView)。通过示例展示了它们在弹出视图和普通视图上的展示方式,并提供了相关代理方法的使用说明。
摘要由CSDN通过智能技术生成

首先看一个时间选择器
本时间选择器是建立在弹出视图上的,也可以在普通视图上显示。
定义一个弹出框(具体的弹出框功能可以在我的另一篇文章可见):

//本方法是一个按钮的点击事件
-(void)customTime{
    UIAlertController *alert;
    if (!alert) {
        alert = [UIAlertController alertControllerWithTitle:@"选择时间" message:@"\n\n\n\n\n\n\n\n\n" preferredStyle:UIAlertControllerStyleActionSheet];//初始化一个标题为“选择时间”,风格是ActionSheet的UIAlertController,其中"\n"是为了给DatePicker腾出空间
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
            //点击确定按钮的事件处理
        }];

        UIDatePicker *datePicker = [[UIDatePicker alloc] init];//初始化一个UIDatePicker
        [alert.view addSubview:datePicker];//将datePicker添加到UIAlertController实例中
        [alert addAction:cancel];//将确定按钮添加到UIAlertController实例中
    }
    [self presentViewController:alert animated:YES completion:^{
    }];//通过模态视图模式显示UI
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值