2012-05-31 33 views
5

下面顯示的鍵盤不是Cocoa提供的默認設置的一部分,因此必須定製。我需要創建一個如下所示的鍵盤。目標C中iPhone的自定義數字和字符鍵盤C

我已經看到了一些使用它的應用程序,我看到一些教程使用一些按鈕在頂部添加了一個自定義欄,但我需要它看起來和功能就像普通鍵盤一樣,但有一排額外的行數字。

如何在Objective C中以編程方式完成?有人可以請指點我正確的方向嗎?

enter image description here

+1

[iPad自定義鍵盤GUI]的可能重複(http://stackoverflow.com/q/2558806/),http://stackoverflow.com/q/4459375/,http://stackoverflow.com/q/ 8322989 /,http://stackoverflow.com/q/1610542/,http://stackoverflow.com/q/5603103/,http://stackoverflow.com/q/789682/,http://stackoverflow.com/ q/9451912,http://stackoverflow.com/q/1332974/ –

+2

基本上[搜索「自定義iphone鍵盤」]的整個第一頁(http://stackoverflow.com/search?q=custom+iphone+鍵盤)。 –

回答

2

你的問題的圖像是從5RowQWERTY項目:http://code.google.com/p/networkpx/wiki/Using_5RowQWERTY

這個項目只能越獄設備上(只要我可以告訴),當然使用私有的API,使得它不能接受的應用商店。如果這些限制與你確定,那麼就使用該項目。它會安裝一個新的鍵盤佈局文件(layout.plist)。

如果您想在非越獄設備上運行,或將您的應用放在應用商店中,那麼您將無法使用該方法。我看到三個選項:

  1. 周圍挖在鍵盤的視圖層次結構出現後(它有自己的UIWindow所以與[[UIApplication sharedApplication] windows]陣列啓動),並添加自己的數字按鈕。這是很多工作,做的很好,很可能會被蘋果拒絕。

  2. 從頭開始重新實現鍵盤。如果您想要支持多種鍵盤佈局並真正匹配系統鍵盤的感覺和行爲,這是一項巨大的工作量。

  3. 放棄,只是將inputAccessoryView設置爲一排數字按鈕。這很容易。

我的建議是除了選項3之外的任何東西都是浪費時間。只需使用inputAccessoryView即可顯示數字欄,然後轉到應用程序的某些部分,爲用戶增加實際價值。

+0

是的,這是正確的,那是我獲得圖像的地方。我的問題是如何做到的。絕對不能有越獄或拒絕的應用程序。聽起來像是痛苦的選擇2也許是我必須遵循的那個,因爲客戶肯定想要那個鍵盤。謝謝! –

1

這是一個非常開放式的問題。你基本上問「如何在iOS中創建自定義視圖?」

這裏有幾點入手:

  1. 你創建具有系統的默認鍵盤外觀的新觀點。您需要爲每個鍵盤按鈕收集資源(創建它們或獲得免費的資源)。

  2. 您可以將所有這些放在IB中。你的觀點不過是一個UIButtons集合。

  3. 要使用鍵盤,您將視圖指定爲inputView。

下面是建立一個自定義inputView教程:http://www.raywenderlich.com/1063/ipad-for-iphone-developers-101-custom-input-view-tutorial

+0

問題不在於如何構建自定義視圖,而是如何將數字按鈕行添加到默認鍵盤。 –

5

你可以使用一個UIToolbar,並添加有0-9按鈕。您甚至可以使用顏色或將其着色爲像iPhone鍵盤一樣灰色,但我無法將其添加到實際的鍵盤視圖中。

//Feel free to change the formatting to suit your needs more 
//And of course, properly memory manage this (or use ARC) 

UIBarButtonItem *my0Button = [[UIBarButtonItem alloc] initWithTitle:@"0" style:UIBarButtonItemStyleBordered target:self action:@selector(addNumberToString:)]; 
UIBarButtonItem *my1Button = [[UIBarButtonItem alloc] initWithTitle:@"1" style:UIBarButtonItemStyleBordered target:self action:@selector(addNumberToString:)]; 

UIToolbar *extraRow = [[UIToolbar alloc] init]; 
extraRow.barStyle = UIBarStyleBlack; 
extraRow.translucent = YES; 
extraRow.tintColor = [UIColor grayColor]; 
[extraRow sizeToFit]; 
NSArray *buttons = [NSArray arrayWithObjects: my0Button, my1Button, etc, nil]; 
[extraRow setItems:buttons animated:YES]; 
textView.inputAccessoryView = extraRow; 



-(void) addNumberToString: (id) sender 
{ 
    //Where current string is the string that you're appending to in whatever place you need to be keeping track of the current view's string. 
    currentString = [currentString stringByAppendingString: ((UIBarButtonItem *) sender).title; 
} 
+0

是的,我相信這是沒有越獄的唯一方法。 –