UITextField
은 10 진수 만 사용자에게 포함하도록되어 있습니다. 키보드 유형을 UIKeyboardTypeDecimalPad
으로 변경했지만이 키보드 레이아웃에 텍스트 필드를 벗어나는 리턴 버튼이 없습니다. 나는 지저분 해 보이는 것처럼 키보드에 별도의 컨트롤을 추가하고 싶지 않습니다. dot
버튼을 반환하고 기능을 변경하려면 어떻게해야합니까? 아니면 다른 대안이 있습니까?UIKeyboardTypeDecimalPad에 반환 버튼을 포함시키는 방법은 무엇입니까?
2
A
답변
9
기본적으로 리턴 키는 10 진수 키보드 유형과 함께 제공되지 않습니다. 다음 코드 스 니펫을 사용하여 해당 내용을 확인하십시오.
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 35.0f)];
toolbar.barStyle=UIBarStyleBlackOpaque;
// Create a flexible space to align buttons to the right
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
// Create a cancel button to dismiss the keyboard
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(resetView)];
// Add buttons to the toolbar
[toolbar setItems:[NSArray arrayWithObjects:flexibleSpace, barButtonItem, nil]];
// Set the toolbar as accessory view of an UITextField object
_yourTextField.inputAccessoryView = toolbar;
희망이 있습니다. 해피 코딩 !!
+0
간단하고 효율적입니다. –
내장 된 키보드의 기본 구현을 변경하는 것은 그만큼 지저분합니다. 관습에 따라 키보드 바깥 쪽을 탭으로 닫거나 키보드 위에 다음/이전 버튼 설정을 추가하는 것이 좋습니다. –
반환 키가 필요한 경우 해당되는 말입니다. 'UIKeyboardTypeNumbersAndPunctuation' 키보드를 구현해야합니다. –
이 링크는 문제를 해결하는 데 유용 할 수 있습니다. [1] : http://stackoverflow.com/questions/6350484/uitextfield-uikeyboardtypedecimalpad-on-ipad –