键盘上添加工具栏

 

- (void)viewDidLoad

{

    [super viewDidLoad];

  

    UIToolbar *toolbar =[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [[UIApplication sharedApplication] keyWindow].bounds.size.width, 40)];

    toolbar.barStyle = UIBarStyleDefault;

 

    UIBarButtonItem *spaceItemLeft = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    UIBarButtonItem *doneBarButton = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(confirmInput)];

    [toolbar setItems:[NSArray arrayWithObjects:spaceItemLeft,doneBarButton,nil]];

 

    _contentTextView.inputAccessoryView = toolbar;  

 

}

 

- (void)confirmInput

{

    [self.view endEditing:YES];

 

}

你可能感兴趣的:(工具)