是否可以向UIDatePickerView添加「完成」按鈕,以便用戶可以點擊該按鈕以關閉視圖。將按鈕添加到UIDatePicker
2
A
回答
8
你應該創建一個UIView來保存選擇器和你需要的按鈕,然後當你需要輸入日期時將該視圖動畫到可見屏幕中,當點擊該按鈕時將其動畫化。我已經使用了這樣的方案,其中按鈕實際上是日期標籤,並且點擊開始或結束日期編輯。
8
我張貼的代碼,請聲明是不宣而按它們的類型休息,你會完成它。希望這會有所幫助的對象...
#pragma mark DatePickerView
UIImagePickerController* imagePickerController;
UIDatePicker *theDatePicker;
UIToolbar* pickerToolbar;
UIActionSheet* pickerViewDate;
-(void)DatePickerView
{
pickerViewDate = [[UIActionSheet alloc] initWithTitle:@"How many?"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
theDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
theDatePicker.datePickerMode = UIDatePickerModeDate;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]autorelease]];
[dateFormatter setDateFormat:@"dd MMM yyyy"];
//[dateFormatter setDateFormat:@"MM/dd/YYYY"];
//[theDatePicker release];
[theDatePicker addTarget:self action:@selector(dateChanged) forControlEvents:UIControlEventValueChanged];
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle=UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(DatePickerDoneClick)];
[barItems addObject:flexSpace];
[pickerToolbar setItems:barItems animated:YES];
[pickerViewDate addSubview:pickerToolbar];
[pickerViewDate addSubview:theDatePicker];
[pickerViewDate showInView:self.view];
[pickerViewDate setBounds:CGRectMake(0,0,320, 464)];
}
-(IBAction)dateChanged{
NSDateFormatter *FormatDate = [[NSDateFormatter alloc] init];
[FormatDate setLocale: [[[NSLocale alloc]
initWithLocaleIdentifier:@"en_US"] autorelease]];
[FormatDate setDateFormat:@"MM/dd/YYYY"];
SelectedTextField.text = [FormatDate stringFromDate:[theDatePicker date]];
}
-(BOOL)closeDatePicker:(id)sender{
[pickerViewDate dismissWithClickedButtonIndex:0 animated:YES];
[pickerToolbar release];
[pickerViewDate release];
[SelectedTextField resignFirstResponder];
return YES;
}
-(IBAction)DatePickerDoneClick{
[self closeDatePicker:self];
tableview.frame=CGRectMake(0, 44, 320, 416);
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
// returns the number of rows
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return 30;
// return [pickerViewArray count];
}
做的修改按要求。這是100%運行的代碼在類似的應用幾乎使用我
編碼快樂......
1
這是取消的UIDatePicker一個示範項目/完成按鈕:https://github.com/lenhhoxung86/CustomDatePicker
0
一個更加個性化UIToolbar和的UIDatePicker項目。可能有幫助: https://github.com/anatoliyv/SMDatePicker
相關問題
- 1. 將按鈕添加到jtable
- 2. 將按鈕添加到UITableView
- 3. 將按鈕添加到jtable
- 4. 將按鈕添加到MKPointAnnotation
- 5. 將按鈕添加到JPanel
- 6. 將按鈕添加到UILabel
- 7. 將按鈕添加到QTableview
- 8. 將OnGestureListener添加到按鈕?
- 9. 將按鈕添加到ListActivity
- 10. 將按鈕添加到UIScrollview
- 11. 將按鈕添加到infoWindow
- 12. 將按鈕添加到BrowseFragment
- 13. 將UIGesture添加到按鈕
- 14. 將ActionListener添加到按鈕
- 15. 將按鈕添加到JScrollpane
- 16. 將按鈕添加到gridview
- 17. 將按鈕添加到ViewPager
- 18. 將按鈕添加到uitextfield
- 19. 將按鈕添加到ListActivity
- 20. 將按鈕添加到JDesktopPane
- 21. 試圖將內聯UIDatePicker添加到UITableViewCell
- 22. UIDatePicker:將約束添加到時間
- 23. 將DB記錄添加到按鈕中
- 24. 將圖標添加到輸入按鈕
- 25. 將CSS類添加到表單按鈕
- 26. 將圖片添加到按鈕
- 27. 將按鈕添加到導航欄
- 28. 將按鈕添加到QComboBox或QCompleter中
- 29. 將單選按鈕添加到Tkinter
- 30. 將自定義按鈕添加到SlickGrid?
thnx。我一直在想,只是想確保 – humblePilgrim 2010-09-02 08:09:32
Thanx我得到它的工作 – humblePilgrim 2010-09-04 04:21:31