I have a UISearchBar
whose appearance I want to customise. The suggestion in this post worked before the update to iOS 7. But now I'm not sure how to do it. I mainly want to customise the Cancel button. Does anybody know how?
Asked
Active
Viewed 998 times
1

Community
- 1
- 1

Rameez Hussain
- 6,414
- 10
- 56
- 85
-
Question answered here: http://stackoverflow.com/questions/18956255/ios-change-the-title-of-cancel-button-in-uisearchbar/18956420 – Guy Kogus Sep 24 '13 at 10:00
-
Doesn't work in iOS 7. The person who has answered that question has mentioned that he has only tried it on iOS 6. – Rameez Hussain Sep 24 '13 at 10:38
-
1Look at my answer to that question. Tried it and it works on iOS 7 :) – Guy Kogus Sep 24 '13 at 11:10
-
The recursive approach worked! Thank you. Maybe you should post it here so I can accept the answer. :) – Rameez Hussain Sep 24 '13 at 11:31
1 Answers
2
You need to search for the button recursively. This should be a fail-safe way to do it:
- (void)viewDidLoad
{
[super viewDidLoad];
[self convertButtonTitle:@"Cancel" toTitle:@"Annuller" inView:self.searchBar];
}
- (void)convertButtonTitle:(NSString *)from toTitle:(NSString *)to inView:(UIView *)view
{
if ([view isKindOfClass:[UIButton class]])
{
UIButton *button = (UIButton *)view;
if ([[button titleForState:UIControlStateNormal] isEqualToString:from])
{
[button setTitle:to forState:UIControlStateNormal];
}
}
for (UIView *subview in view.subviews)
{
[self convertButtonTitle:from toTitle:to inView:subview];
}
}
I've tested this on iOS 7 only, but it works and should do so for iOS 6 too.

Guy Kogus
- 7,251
- 1
- 27
- 32
-
Thanks, also, I can't seem to be able to change the frame of the cancel button. Any idea why? – Rameez Hussain Sep 24 '13 at 13:35
-
Nope, haven't had a chance to try that. Maybe try changing it in `viewDidLayoutSubviews`? – Guy Kogus Sep 24 '13 at 14:34
-
1
-