本文摘自http://blog.csdn.net/hitwhylz/article/details/29263027
自定义键盘
源码可以到我的github中下载:https://github.com/colin1994/myKeyboard.git
可以通过自定义键盘, 在键盘上加入你需要的功能, 即可。
效果如下:
代码如下:
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- if (self.keyboardToolbar == nil)
- {
- self.keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 38.0f)];
- self.keyboardToolbar.barStyle = UIBarStyleBlackTranslucent;
- UIBarButtonItem *previousBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"前进", @"")
- style:UIBarButtonItemStyleBordered
- target:self
- action:@selector(previousField:)];
- UIBarButtonItem *nextBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"后退", @"")
- style:UIBarButtonItemStyleBordered
- target:self
- action:@selector(nextField:)];
- UIBarButtonItem *spaceBarItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
- target:nil
- action:nil];
- UIBarButtonItem *doneBarItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"隐藏", @"")
- style:UIBarButtonItemStyleDone
- target:self
- action:@selector(resignKeyboard:)];
- [self.keyboardToolbar setItems:[NSArray arrayWithObjects:previousBarItem, nextBarItem, spaceBarItem, doneBarItem, nil]];
- }
- self.myTextView.inputAccessoryView = self.keyboardToolbar;
- }
- #pragma mark - your code
- - (void)resignKeyboard:(id)sender
- {
- [self.myTextView resignFirstResponder];
- }
- - (void)previousField:(id)sender
- {
- }
- - (void)nextField:(id)sender
- {
- }