2012-05-31 34 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

是的,我相信这是没有越狱的唯一方法。 –