Custom InputView for UISearchBar doesn't work in iOS7

♀尐吖头ヾ 提交于 2019-11-30 23:42:13

The searchBar sub views hierarchy has been changed in iOS7, try the below:

iOS7:

NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];

iOS6 and before:

NSArray *searchBarSubViews =  self.searchBar.subviews;

Try below updated function:

NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for(int i =0; i<[searchBarSubViews count]; i++) {
    if([[searchBarSubViews objectAtIndex:i] isKindOfClass:[UITextField class]])
    {
        UITextField* search=(UITextField*)[searchBarSubViews objectAtIndex:i];
        [search setFont:[UIFont fontWithName:@"MyCustomFont" size:15]];
        search.delegate = self;

        [search setInputView:self.customKeyboard];
        [self.customKeyboard setTextView:search];
    }
}
[self.sBar reloadInputViews];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!