键盘自定义toolbar(inputAccessoryView属性实现)

实现代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _myTextField.inputAccessoryView = [self setUpSearchBarAccessoryView];
    
}
#pragma mark - private methods
- (UIToolbar *)setUpSearchBarAccessoryView
{
    // set up searchBar's toolbar
    UIToolbar *toolbar = [[UIToolbar alloc] init];
    toolbar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);
    [toolbar setBarStyle:UIBarStyleDefault];
    
    UIBarButtonItem *flexBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    
    UIBarButtonItem *doneBarButton = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleBordered target:self action:@selector(doneButtonIsClicked:)];
    NSArray *barButtonItems = @[flexBarButton, doneBarButton];
    toolbar.items = barButtonItems;
    return toolbar;
}
- (void)doneButtonIsClicked:(id)sender
{
    [_myTextField resignFirstResponder];
}

实现效果图:

 

 

键盘监听,获取键盘的高度,NSNotificationCenter

http://www.cnblogs.com/qingjoin/archive/2012/09/12/2681659.html

 

 

posted on 2016-06-22 13:12  快乐加油站789  阅读(539)  评论(0编辑  收藏  举报

导航