zoukankan      html  css  js  c++  java
  • 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. }
  • 相关阅读:
    Android Fragment与Activity通讯详解
    Fragment之间的交互
    理解Fragment的生命周期
    Android 利用ViewPager、Fragment、PagerTabStrip实现多页面滑动效果
    【APP UI 设计模式】(一)APP UI 设计原则和流程
    白话经典算法系列之六 高速排序 高速搞定
    究竟什么是推荐?
    Mongo散记--聚合(aggregation)& 查询(Query)
    C/C++程序猿必须熟练应用的开源项目
    PL/SQL连接oracle数据库
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3163102.html
Copyright © 2011-2022 走看看