iOS UItextView消除键盘

本文只介绍在键盘上面增加一个按钮的方法:

UIToolbar *topView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, IPHONE_WIDTH, 30)];
    [topView setBarStyle:UIBarStyleDefault];
    UIBarButtonItem *btnSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(dismissKeyBoard)];
    NSArray *buttonArray = [NSArray arrayWithObjects:btnSpace,doneButton, nil];
    [topView  setItems:buttonArray];
    [self.textViewDetails setInputAccessoryView:topView];
//关闭键盘
-(void) dismissKeyBoard{
    [self.textViewDetails resignFirstResponder];
}

 

posted @ 2015-07-02 16:23  暗夜追星  阅读(451)  评论(0)    收藏  举报