美文网首页
六.警告框与时间选择器的完美配合

六.警告框与时间选择器的完美配合

作者: 择一城终老_蜗牛 | 来源:发表于2016-11-23 17:36 被阅读0次

点击按钮 要求:
(1)早上8.00到下午18.00 之内可选择时间 之外不允许
(2)小于当前时间的不能选

-(void)Time
{
    //获取系统时间
    
    NSDate * senddate=[NSDate date];
    
    
    NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"HH"];
    
    int  locationString =[[dateformatter stringFromDate:senddate] intValue];
    
    //判断时间(8 - 18)
    if (locationString >= 8 && locationString <= 18)
    {
        NSLog(@"在时间范围内");
        
        UIAlertController* alertVc=[UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n" message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
        UIDatePicker* datePicker=[[UIDatePicker alloc]init];
        datePicker.datePickerMode = UIDatePickerModeDateAndTime;
        UIAlertAction* ok=[UIAlertAction actionWithTitle:@"确认" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction *action) {
            //            nsdate 类型的时间
            NSDate* chosedate=[datePicker date];
            NSDateFormatter* formatter=[[NSDateFormatter alloc]init];
            //选中最小时间是现在
            NSDate *  nowDate=[NSDate date];
            datePicker.minimumDate = nowDate;
            
            
            [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
            //            字符串类型的时间
            NSString* curentDatest=[formatter stringFromDate:chosedate];
            //输出选中时间是多少
            NSString *text=curentDatest;
            //选中时间的时间戳是多少
            
            
            NSLog(@"%@",text);
            
            //            选中时间的时间戳
//            NSString *timeSp=[NSString   stringWithFormat:@"%ld",(long)[chosedate timeIntervalSince1970]];
            
            
            if ([nowDate timeIntervalSince1970] - [chosedate timeIntervalSince1970] <0)
            {
                NSLog(@"时间能选");
                
                
            }else
            {
                NSLog(@"时间bu能选");
            
            }
        }];
        UIAlertAction* no=[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:nil];
        [alertVc.view addSubview:datePicker];
        [alertVc addAction:ok];
        [alertVc addAction:no];
        [self presentViewController:alertVc animated:YES completion:nil];
        
    }else
    {
      NSLog(@"不在时间范围内");
    }
}```

相关文章

  • 六.警告框与时间选择器的完美配合

    点击按钮 要求:(1)早上8.00到下午18.00 之内可选择时间 之外不允许(2)小于当前时间的不能选

  • Bootstrap警告提示框、徽章、面包屑导航样式

    警告框样式 使用.alert设置警告框基础样式,并使用.alert-success等设置警告框颜色; 在使用了警告...

  • JavaScript 弹窗

    可以在 JavaScript 中创建三种消息框:警告框、确认框、提示框。 警告框 警告框经常用于确保用户可以得到某...

  • 智能表单

    新增的类型: Color 颜色选择器 Date 日期选择框 Datetime 日期时间选择框 ...

  • 警告框与弹出框的处理

    alert/confirm/prompt按钮弹出框操作的主要方法如下: alert按钮的操作步骤如下: (1)调用...

  • 警告框处理

    弹出警告框,我们用switch_to.alert方法定位到警告框,然后再执行我们想要的操作 获取警告框文本text...

  • [iOS学习]警告框和操作表

    警告框 iOS中警告框给用户警告或提示,最多两个按钮,超过两个就应该使用操作表。由于在iOS中警告框是模态的,因此...

  • 第九谈:警告提示框

    本节课我们来开始学习 Bootstrap 的警告框样式以及组件的使用。 一.警告框样式 使用.alert 设置警告...

  • UIDatePicker(UIPickView)

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

  • 警告框

网友评论

      本文标题:六.警告框与时间选择器的完美配合

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