iOS - 自定义键盘按钮,如evernote

时间:2017-01-28 12:18:18

标签: ios objective-c xcode keyboard

我打算创建“按钮”来编辑文本视图中的文本,如evernote。这样的事情:

enter image description here

我不知道怎么办:(

1 个答案:

答案 0 :(得分:1)

您可以尝试以下代码:

  

注意:不要忘记make textView delegate。

UIToolbar *keyboardDoneButtonView = [[UIToolbar alloc] init];
[keyboardDoneButtonView sizeToFit];

UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                               style:UIBarButtonItemStylePlain target:self
                                                              action:@selector(doneClicked:)];

[keyboardDoneButtonView setItems:[NSArray arrayWithObjects:flexible, doneButton, nil]];


self.textView.inputAccessoryView = keyboardDoneButtonView;

IBAction功能:

- (IBAction)doneClicked:(id)sender
{
    NSLog(@"Done Clicked.");
    [self.view endEditing:YES];
}