iOS 7 and later, the UITextField in UISearchBar should be found using the way: ui
1 // Set Search Button Title to Done 2 for (UIView *searchBarSubview in [self.searchBar subviews]){ if ([searchBarSubview conformsToProtocol:@protocol(UITextInputTraits)]) { // Before iOS 7.0 5 @try { [(UITextField *)searchBarSubview setReturnKeyType:UIReturnKeyDone]; [(UITextField *)searchBarSubview setKeyboardAppearance:UIKeyboardAppearanceAlert]; } @catch (NSException * e) { // ignore exception11 } } else { // iOS 7.014 for(UIView *subSubView in [searchBarSubview subviews]){ if([subSubView conformsToProtocol:@protocol(UITextInputTraits)]) { @try { [(UITextField *)subSubView setReturnKeyType:UIReturnKeyDone]; [(UITextField *)searchBarSubview setKeyboardAppearance:UIKeyboardAppearanceAlert]; } @catch (NSException * e) { // ignore exception22 } } } } }
Thanks, code
Blues orm