本文介绍了如何在iOS7中更改UISearchBar的inputView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS6中,我使用以下代码更改UISearchbar的inputView

In iOS6 , I use the below code to change inputView of UISearchbar

for (UIView *view in _searchBar.subviews) {
    if ([view isKindOfClass: [UITextField class]]) {
        UITextField* textField = (UITextField*)view;
        [textField setInputView:_myKeyboard];
        break;
    }
}

iOS7中的UISearchbar发生了变化,我不知道如何找到textField来改变inputView。
请帮忙!谢谢!

UISearchbar in iOS7 had changed, I don't know how to find textField to change inputView.Please help! Thanks!

推荐答案

子视图的层次结构在iOS7中已经更改,因此您可以使用以下代码:

The hierarchy of subview has been changed in iOS7, so you can use the following code:

// subviews
NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for (UIView *view in searchBarSubViews) {
    if([view isKindOfClass:[UITextField class]])
    {
        UITextField* search=(UITextField*)view;
        [search setFont:[UIFont fontWithName:@"MyCustomFont" size:15]];
        search.delegate = self;

        [search setInputView:self.customKeyboard];
        [self.customKeyboard setTextView:search];
    }
}
[self.searchBar reloadInputViews];

这篇关于如何在iOS7中更改UISearchBar的inputView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 01:47