iphone-UI搜索栏上的搜索按钮
我有一个使用UISearchBar的即时搜索功能,所以我认为用“完成”替换键盘上的“搜索”按钮会更明显 有办法吗iphone-UI搜索栏上的搜索按钮,iphone,ipad,Iphone,Ipad,我有一个使用UISearchBar的即时搜索功能,所以我认为用“完成”替换键盘上的“搜索”按钮会更明显 有办法吗 谢谢您可以更改UISearchBar对象的键盘类型属性。但是,无法直接更改returnKeyType。您可以对其进行筛选并手动更改。查看UISearchBar的文档,看看是否可以找到您正在寻找的返回键类型。我通过以下方式完成: // -- Basic UISearchBar setup. self.theSearchBar = [[UISearchBar alloc] initW
谢谢您可以更改UISearchBar对象的
键盘类型
属性。但是,无法直接更改returnKeyType
。您可以对其进行筛选并手动更改。查看UISearchBar的文档,看看是否可以找到您正在寻找的返回键类型。我通过以下方式完成:
// -- Basic UISearchBar setup.
self.theSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,0,320,38)];
[self.theSearchBar setDelegate:self];
[self.view addSubview:self.theSearchBar];
// -- Customize the returnKeyType of the search bar's nested UITextField.
UITextField *searchBarTextField = [[self.theSearchBar subviews] objectAtIndex:1];
searchBarTextField.returnKeyType = UIReturnKeyGo;
希望这是有帮助的。这种方法(即通过索引获取子视图)将来可能会失败,但目前效果良好。不要依赖它作为第二个子视图,请使用isKindOfClass:方法进行检查。这将是更多的iOS更新证明这种方式
for (UIView *subview in self.theSearchBar.subviews) {
if ([subview isKindOfClass:[UITextField class]]) {
[(UITextField *)subview setReturnKeyType:UIReturnKeyGo];
break;
}
}
这适用于iOS 6
UITextField *searchBarTextField = [[searchBarObj subviews] objectAtIndex:1];
searchBarTextField.returnKeyType = UIReturnKeyDefault;
[searchBarTextField setEnablesReturnKeyAutomatically:NO];
这适用于iOS 7
for (UIView *subview in self.searchBar.subviews)
{
for (UIView *subSubview in subview.subviews)
{
if ([subSubview conformsToProtocol:@protocol(UITextInputTraits)])
{
UITextField *textField = (UITextField *)subSubview;
[textField setKeyboardAppearance: UIKeyboardAppearanceAlert];
textField.returnKeyType = UIReturnKeyDone;
break;
}
}
}
谢谢,但不幸的是搜索栏没有此属性…:(
for (UIView *subview in self.searchBar.subviews)
{
for (UIView *subSubview in subview.subviews)
{
if ([subSubview conformsToProtocol:@protocol(UITextInputTraits)])
{
UITextField *textField = (UITextField *)subSubview;
[textField setKeyboardAppearance: UIKeyboardAppearanceAlert];
textField.returnKeyType = UIReturnKeyDone;
break;
}
}
}