首页 > 代码库 > ISO UiView和UiDatePiceker的搭配
ISO UiView和UiDatePiceker的搭配
效果图如下:
功能代码如下:
//datepicker
UIView *myView=[[UIView alloc]initWithFrame:CGRectMake(20, 100, 280, 224)];
myView.layer.borderWidth=2;
myView.layer.borderColor=[[UIColor blackColor]CGColor];
myView.backgroundColor=[UIColor grayColor];
UILabel *l=[[UILabel alloc]initWithFrame:CGRectMake(2, 2, 276, 20)];
l.text=@"请您选择时间:";
l.backgroundColor=[UIColor blackColor];
l.textColor=[UIColor redColor];
[myView addSubview:l];
UIDatePicker *datepicker=[UIDatePicker new];
datepicker.frame=CGRectMake(0, 24, 280, 150);
datepicker.datePickerMode=UIDatePickerModeDateAndTime;
[myView addSubview:datepicker];
UIButton *btnok=[UIButton buttonWithType:UIButtonTypeRoundedRect];
btnok.frame=CGRectMake(50, 180, 80, 30);
[btnok setTitle:@"确 定" forState:UIControlStateNormal];
btnok.backgroundColor=[UIColor blackColor];
[btnok setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[btnok addTarget:self action:@selector(btnokAction) forControlEvents:UIControlEventTouchUpInside];
[myView addSubview:btnok];
[self.view addSubview:myView];
按钮时间如下:
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"信息提示:"
message:@"收到"
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
}