2010-06-05 70 views
1

目前我有一個文本框,它拉起了一個NumberPad鍵盤輸入。iPhone SDK NumberPad自定義inputView完成按鈕

我想要NumberPad鍵盤佈局,但我需要一個按鈕來辭去響應者。

有沒有辦法對UITextField進行編碼,使其具有NumberPad鍵盤,鍵盤左側空白處被替換爲「完成」,「發送」或「開始」按鈕。

或者我需要爲UITextField創建一個自定義inputView嗎?

我會想,因爲NumberPad上有一個空白鍵,蘋果會使它對某些東西有用。

+0

[重複的問題,請看這裏(http://stackoverflow.com/questions/584538/how-to-show-button-done-on-number-pad-on -iphone)[這裏有一個鏈接來創建這樣一個按鈕](http://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key) – vodkhang 2010-06-05 02:03:23

回答

0

你需要現在做一個自定義的輸入視圖,並將其分配給你的文本字段的inputview屬性。我目前正在研究它,但這是正確的,經過批准的方式。看起來只是爲了更改一個按鈕而過度使用。

+1

http ://www.neoos.ch/news/46-development/54-uikeyboardtypenumberpad-and-the-missing-return-key 已更新iOS4.0的內容 – OscarTheGrouch 2010-07-19 19:21:25

2

只需嘗試將一個UIToolBar作爲文本字段的inputAccessoryView,並將其作爲完成按鈕。在按鈕單擊事件中提供代碼以關閉鍵盤。認爲應該適合你。

或者,如果你想有繪製在你可以搜索在這裏得到解決

2

如果使用phonePad需要空的按鈕鍵盤自定義按鈕。但是,您可以添加inputAccessoryView'Apply'和'Cancel'按鈕,然後關閉數字鍵盤。

inputAccessoryView

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; 
    numberToolbar.barStyle = UIBarStyleBlackTranslucent; 
    numberToolbar.items = [NSArray arrayWithObjects: 
         [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)], 
         [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], 
         [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)], 
        nil]; 
    [numberToolbar sizeToFit]; 
    numberTextField.inputAccessoryView = numberToolbar; 
} 

-(void)cancelNumberPad{ 
    [numberTextField resignFirstResponder]; 
    numberTextField.text = @""; 
} 

-(void)doneWithNumberPad{ 
    NSString *numberFromTheKeyboard = numberTextField.text; 
    [numberTextField resignFirstResponder]; 
}