F L*_*F L 5 cocoa-touch objective-c uikeyboard ios
下面显示的键盘不是Cocoa提供的默认值的一部分,因此必须自定义构建.我需要创建一个类似下面的键盘.
我已经看到一些使用它的应用程序,我看到一些教程在顶部添加了一些自定义栏和一些按钮,但我需要它看起来和功能就像一个普通的键盘,但有一排额外的数字.
如何在Objective C中以编程方式完成?有人可以指点我正确的方向吗?

小智 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;
}
Run Code Online (Sandbox Code Playgroud)
您问题中的图片来自 5RowQWERTY 项目:http://code.google.com/p/networkpx/wiki/Using_5RowQWERTY
该项目仅适用于越狱设备(据我所知),并且肯定使用私有 API,这使得应用商店无法接受。如果您可以接受这些限制,那么就使用该项目。它会安装新的键盘布局文件 ( layout.plist)。
如果你想在非越狱设备上运行,或者将你的应用程序放在应用程序商店中,你将无法使用该方法。我看到三个选项:
在键盘出现后,在键盘的视图层次结构中进行挖掘(它有自己的视图层次UIWindow结构,因此从[[UIApplication sharedApplication] windows]数组开始)并添加您自己的数字按钮。这是一项繁重的工作,很难做好,而且很可能会被苹果拒绝。
从头开始重新实现键盘。如果您想支持多种键盘布局并真正匹配系统键盘的感觉和行为,这是一项巨大的工作量。
放弃,直接设置inputAccessoryView为一排数字按钮。这很容易。
我的建议是,除了选项 3 之外的任何方法都是浪费时间。只需使用 来inputAccessoryView显示数字栏,然后转到应用程序中为用户增加实际价值的部分。
| 归档时间: |
|
| 查看次数: |
6842 次 |
| 最近记录: |