2014. 10. 28. 17:50ㆍ개발자료/iOS
+ UIActionSheet를 이용해서 UIDatePicker 띄우기
//--xx test.h
UIActionSheet *m_actionSheet;
UIDatePicker *m_datePicker;
//--xx test.m
- (void)clickDatePicker{
m_actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
m_datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 44, 0, 0)];
m_datePicker.datePickerMode = UIDatePickerModeDate;
m_datePicker.date = [NSDate date];
UIToolbar *datePickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
datePickerToolbar.barStyle = UIBarStyleBlackOpaque;
[datePickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *btnFlexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nilaction:nil];
[barItems addObject:btnFlexibleSpace];
UIBarButtonItem *btnCancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:selfaction:@selector(doDatePickerCancelClick)];
[barItems addObject:btnCancel];
UIBarButtonItem *btnDone = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:selfaction:@selector(doDatePickerCancelDone:)];
btnDone.tag = iTag;
[barItems addObject:btnDone];
[datePickerToolbar setItems:barItems animated:YES];
[m_actionSheet addSubview:datePickerToolbar];
[m_actionSheet addSubview:m_datePicker];
[m_actionSheet showInView:self.view];
[m_actionSheet setBounds:CGRectMake(0, 0, 320, 500)];
}
- (void)doDatePickerCancelClick{
[m_actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
- (void)doDatePickerCancelDone:(UIBarButtonItem*)sender{
[m_actionSheet dismissWithClickedButtonIndex:0 animated:YES];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy년 MM월 dd일 E요일"];
NSLog(@"date:%@", [dateFormatter stringFromDate:m_datePicker.date]);
//--xx date:2014년 02월 21일 금요일 형식으로 출력
}
'개발자료 > iOS' 카테고리의 다른 글
UITableView (0) | 2014.10.28 |
---|---|
핫스팟 상태체크(꼼수) (0) | 2014.10.28 |
NSDate, NSDateFormat (0) | 2014.10.28 |
nan 값 체크하기 (0) | 2014.10.28 |
UIWebView (0) | 2014.10.28 |