gpt4 book ai didi

ios - 如何在 iOS7 中更改 UISearchBar 的 inputView?

转载 作者:行者123 更新时间:2023-12-01 19:04:55 25 4
gpt4 key购买 nike

在 iOS6 中,我使用下面的代码来改变 UISearchbar 的 inputView

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

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

最佳答案

iOS7 中 subview 的层次结构发生了变化,所以可以使用如下代码:

// 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];

关于ios - 如何在 iOS7 中更改 UISearchBar 的 inputView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20278677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com