I know people asked this before and I found this solution:
for (UIView *subview in searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top-bar.png"]];
[searchBar insertSubview:bg aboveSubview:subview];
[subview removeFromSuperview];
break;
}
}
I’m just not sure if it include some private API that apple will reject, or is there a better way to do this?
- I’m still supporting ios 4, so no ios 5 only APIs
Apple does not encourage people who are using private undocumented apis.
But still you can use subclassing feature in your application. I have used this kind of subclassing UISearchBarBackground. Apple was accepted my application which was in live. So no issues of using above code in your application.