[英]How to change inputView of UISearchBar in iOS7?
In iOS6 , I use the below code to change inputView of UISearchbar 在iOS6中,我使用下面的代码来更改UISearchbar的inputView
for (UIView *view in _searchBar.subviews) {
if ([view isKindOfClass: [UITextField class]]) {
UITextField* textField = (UITextField*)view;
[textField setInputView:_myKeyboard];
break;
}
}
UISearchbar in iOS7 had changed, I don't know how to find textField to change inputView. iOS7中的UISearchbar已经改变,我不知道如何找到textField来改变inputView。 Please help!
请帮忙! Thanks!
谢谢!
The hierarchy of subview has been changed in iOS7, so you can use the following code: 子视图的层次结构已在iOS7中更改,因此您可以使用以下代码:
// 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];
Use following code : 使用以下代码:
NSArray *subViewsOfSearchBar = [[self.YOurSearchBar.subviews objectAtIndex:0] subviews];
for(int i =0; i< subViewsOfSearchBar.count; i++) {
if([[subViewsOfSearchBar objectAtIndex:i] isKindOfClass:[UITextField class]])
{
UITextField *searchTxtField=(UITextField*)[subViewsOfSearchBar objectAtIndex:i];
[searchTxtField setInputView:self.customKeyboard];
}
}
[self.searchBar reloadInputViews];
Try this code : 试试这段代码:
for (UIView *view in _searchBar.inputView.subviews) {
if ([view isKindOfClass: [UITextField class]]) {
UITextField* textField = (UITextField*)view;
[textField setInputView:_myKeyboard];
break;
}
}
in iOS 7 subview is not working. 在iOS 7子视图不起作用。 From iOS7 UI objects have a extra wrapper/container.
从iOS7 UI对象有一个额外的包装器/容器。 May be this code will help you.
可能这段代码会对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.