uitextfieldには日付が書かれています..標準キーボードの代わりにuidatepickerをページの下部に表示するにはどうしたらいいですか? ありがとうございましたios UITextFieldをuidatepickerで編集する
6
A
答えて
4
クラスがUITextFieldDelegate
プロトコルを実装していることを確認してください。私はUIDatePicker
を含む別のUIViewController
を使用することをお勧めします
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
//check if it is the UITextField you don't want the keyboard for
if (textField != dateTextField)
return TRUE;
//present your UIDatePicker
//see instructions below
//Return false to prevent the keyboard from appearing.
return FALSE;
}
し、それを表示するためにpresentModalViewController
を使用します。次に、FALSEを返すためにshouldBeginEditing
デリゲートメソッドをオーバーライドします。これはユーザインタフェースガイドラインに準拠しています。
5
UITextFieldは、このためのメカニズムを提供します。 inputViewとは別のビュー(datepickerのようなもの)を設定できるはずです。この記事を参照してください。
3
あなたは、次のコードを使用することができます。
//first of all, you have to declare the datePicker and then use the following code;
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
[dateLabel resignFirstResponder]; //the textField that you will set the selected date
datePicker = [[UIDatePicker alloc] init]; //declared uidatepicker component
pickerViewDate = [[UIActionSheet alloc] initWithTitle:@"Select the date!"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
datePicker.datePickerMode = UIDatePickerModeDate; //set your spesific mode
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]]; //or another LocaleIdentifier instead of en_US
[dateFormatter setDateFormat:@"dd.MM.yyyy"]; //desired format
[datePicker addTarget:self action:@selector(dateChanged) forControlEvents:UIControlEventValueChanged]; //the function would be fired when user change the date in datePicker
//now preparing the toolbar which will be displayed at the top of the datePicker
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(doneButtonClicked)]; //barbutton item is "DONE" and doneButtonClicked action will be fired when user clicks the button.
[barItems addObject:flexSpace]; // set the left of the bar
[pickerToolbar setItems:barItems animated:YES];
[pickerViewDate addSubview:pickerToolbar];
[pickerViewDate addSubview:datePicker];
[pickerViewDate showInView:self.view];
[pickerViewDate setBounds:CGRectMake(0,0,320, 464)]; //you can change the position
}
などの追加アクション。
-(IBAction)dateChanged{
NSDateFormatter *FormatDate = [[NSDateFormatter alloc] init];
[FormatDate setLocale: [[NSLocale alloc]
initWithLocaleIdentifier:@"en_US"]];
[FormatDate setDateFormat:@"dd.MM.yyyy"];
dateLabel.text = [FormatDate stringFromDate:[datePicker date]];
}
-(BOOL)closeDatePicker:(id)sender{
[pickerViewDate dismissWithClickedButtonIndex:0 animated:YES];
[dateLabel resignFirstResponder];
return YES;
}
-(IBAction)doneButtonClicked{
[self closeDatePicker:self];
}
関連する問題
- 1. iOS 6.0でマルチバイトキーボードを使用してuitextfieldを編集するとき
- 2. UITextfieldでの編集モードの問題
- 3. uitextfieldの編集中にuitableviewでスクロールを止める方法
- 4. iOS 5で逆ジオコーディングを編集する
- 5. 別のテーブルビューセルでUITextFieldの編集をプログラムで開始します
- 6. IOS ContactUIは私Xamarin iOSアプリで編集
- 7. UITableViewCell内のUITextFieldでNSManagedObjectを編集します。
- 8. 編集後にUITextFieldブレンドを背景にする方法は?
- 9. ios uidatepicker with presentModalViewController
- 10. uitextfieldを編集した後、コレクションビューでセルを選択
- 11. ユーザーがUITextFieldで入力した後に編集不可能なラベルを追加する - iOS
- 12. カスタム[編集]メニューのiOSスウィフト
- 13. IOSのビデオ編集ライブラリ
- 14. iOSのXcodeの:編集ルートビューコントローラ
- 15. iOS EKRecurrenceRule例外と編集
- 16. 編集開始時にUITextFieldを伸ばす方法
- 17. 編集時にuitextfieldが戻り値のキータイプを返す
- 18. 編集中にUITextFieldがテキストを切り捨てます。
- 19. UIDatePicker NSRangeExceptionクラッシュiOS 11
- 20. UIButtonのクリックでUITextfieldを追加して編集可能にする方法
- 21. UITextfieldのテキストが編集中に移動しています
- 22. 編集をどのようにすればいいですか? UITextFieldで?
- 23. UITextfieldは編集時のコンテンツを表示しません。
- 24. iOS 8.1のUITextFieldは、一部のフォントを使用しているときに、編集モードと非編集モードの垂直方向の配置が異なる
- 25. iOSでリアルタイムでビデオを編集してプレビューする
- 26. UIButtonを作成するとUITextFieldがテキストの編集を開始します
- 27. Wordpress、ホームページの編集を編集する
- 28. iOS - UIDatePickerの言語をロケールで変更
- 29. iOS UITableViewアクセシビリティを使用した編集
- 30. UITextField内の編集可能なスクロール可能性
この方法では、画面の下部に日付ピッカーが必要で、画面全体を覆わないようにしたい場合は問題があります。基になるビューはそこにはないので、モーダルに表示されたビューコントローラを透明にすることはできません。 http://stackoverflow.com/questions/849458/transparent-modal-view-on-navigation-controller – kris