Jim*_*m B 54 iphone button title uisearchbar
在UISearchBar控件中,是否可以将键盘的搜索键标题更改为"完成"?
Run*_*oop 99
对于名为tablesearchbar的搜索栏:
// Set the return key and keyboard appearance of the search bar
for (UIView *searchBarSubview in [tableSearchBar subviews]) {
if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) {
@try {
[(UITextField *)searchBarSubview setReturnKeyType:UIReturnKeyDone];
[(UITextField *)searchBarSubview setKeyboardAppearance:UIKeyboardAppearanceAlert];
}
@catch (NSException * e) {
// ignore exception
}
}
}
Run Code Online (Sandbox Code Playgroud)
pic*_*ick 48
至少对于iOS 8,简单地说:
[self.searchBar setReturnKeyType:UIReturnKeyDone];
Run Code Online (Sandbox Code Playgroud)
Gre*_*aun 43
从iOS 7 beta 5开始,Run Loop的回答对我不起作用,但是这样做了:
for(UIView *subView in [searchBar subviews]) {
if([subView conformsToProtocol:@protocol(UITextInputTraits)]) {
[(UITextField *)subView setReturnKeyType: UIReturnKeyDone];
} else {
for(UIView *subSubView in [subView subviews]) {
if([subSubView conformsToProtocol:@protocol(UITextInputTraits)]) {
[(UITextField *)subSubView setReturnKeyType: UIReturnKeyDone];
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
the*_*ker 18
一个更有用的提示,运行循环代码(在"@try")部分.
当文本字段为空时,这会启用"完成"按钮:
UITextField *tf = (UITextField *)searchBarSubview;
tf.enablesReturnKeyAutomatically = NO;
Run Code Online (Sandbox Code Playgroud)
Har*_*kar 13
为Swift更改UISearchBar的返回键
searchBar.returnKeyType = UIReturnKeyType.done
Run Code Online (Sandbox Code Playgroud)
枚举可用如下
public enum UIReturnKeyType : Int {
case default
case go
case google
case join
case next
case route
case search
case send
case yahoo
case done
case emergencyCall
@available(iOS 9.0, *)
case continue
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
35327 次 |
| 最近记录: |