• ios-王云鹤 把UIdatePicker 嵌入到 UIActionSheet中


    1. 这里简单的解释一下:

      -(void) setUpDatePicker方法用于调用UIDatePicker

      -(void) DatePickerDoneClick:(id) sender方法用于实现隐藏UIdatePicker

      -(void) dateChanged:(id)sender方法实现获取日期结果值的方法。

      如果没有实现效果,别忘记加上协议,这个是比较容易忘记的

    2. -(void) setUpDatePicker
    3. {
    4.     //点击显示时间
    5.     self.actionSheet =[[UIActionSheet alloc] initWithTitle:nil
    6.                                                    delegate:self
    7.                                           cancelButtonTitle:nil
    8.                                      destructiveButtonTitle:nil
    9.                                           otherButtonTitles:nil];
    10.    
    11.     UISegmentedControl*cancelButton =[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"取消"]];
    12.     UISegmentedControl*confirmButton =[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"确定"]];
    13.     [self.actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    14.     // Add the picker
    15.     self.datePicker =[[UIDatePicker alloc] init];
    16.     self.datePicker.datePickerMode =UIDatePickerModeDate;
    17.     [self.datePicker addTarget:self
    18.                         action:@selector(dateChanged:)
    19.               forControlEvents:UIControlEventValueChanged];
    20.     [self.actionSheet addSubview:self.datePicker];
    21.     [self.actionSheet showInView:self.view];
    22.     [self.actionSheet setBounds:CGRectMake(0,0,320,500)];
    23.    
    24.     CGRect pickerRect;
    25.     pickerRect = self.datePicker.bounds;
    26.     pickerRect.origin.y =-50;
    27.     self.datePicker.bounds = pickerRect;
    28.     cancelButton.momentary = YES;
    29.     cancelButton.frame =CGRectMake(10.0f,7.0f, 65.0f, 32.0f);
    30.     cancelButton.segmentedControlStyle =UISegmentedControlStyleBar;
    31.     [cancelButton addTarget:self action:@selector(DatePickerDoneClick:) forControlEvents:UIControlEventValueChanged];
    32.     [self.actionSheet addSubview:cancelButton];
    33.  
    34.     cancelButton.tag =1;
    35.     confirmButton.momentary = YES;
    36.     confirmButton.frame =CGRectMake(245.0f,7.0f, 65.0f, 32.0f);
    37.     confirmButton.segmentedControlStyle =UISegmentedControlStyleBar;
    38.     [confirmButton addTarget:self action:@selector(DatePickerDoneClick:) forControlEvents:UIControlEventValueChanged];
    39.     [self.actionSheet addSubview:confirmButton];
    40.  
    41.     confirmButton.tag =2;
    42.     [self.actionSheet showInView:self.view];
    43.     [self.actionSheet setBounds:CGRectMake(0,0,320, 500)];
    44.    
    45. }
    46.  
    47. -(void)DatePickerDoneClick:(id) sender
    48. {
    49.     UIButton*button =(UIButton*)sender;
    50.     if(button.tag ==1)
    51.     {
    52.         [self.actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    53.     }
    54.    
    55.     if(button.tag ==2)
    56.     {
    57.         [self.actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    58.     }
    59. }
    60.  
    61. -(void) dateChanged:(id)sender
    62. {
    63.     NSDate*dateValue =[NSDate date];
    64.     NSDateFormatter*dateFormatter =[[NSDateFormatter alloc] init];
    65.     [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    66.     dateValue =((UIDatePicker*)sender).date;
    67.    
    68.     self.teleplayDate.text =[dateFormatter stringFromDate:dateValue];//[NSString stringWithFormat:@"%@",dateValue];
    69. }
  • 相关阅读:
    WPF操作ini 文件的读写示例
    WPF调用图片路径,或资源图片
    WPF笔记一
    WPF 获取程序路径的一些方法,根据程序路径获取程序集信息
    10进制转62进制,实现穷举指定位数的所有密码组合(暴力破解)
    匿名对象和object的转换
    构造函数和:this()的应用
    WPF TextBox自动滚动到最户一行
    C#接口的使用场合,接口应用
    读匿名object对象的属性值
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3163102.html
Copyright © 2020-2023  润新知