我知道人们面前问这个,我发现这个解决方案:将UISearchBar背景更改为自定义图像的正确方法是什么?
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;
}
}
我只是不知道这是否有一些私人API,苹果会拒绝,或者是有更好的方法来做到这一点?
- 我仍然支持iOS 4的,所以没有iOS 5中唯一的API
可能重复的[如何自定义UISearchBar](http://stackoverflow.com/questions/6201406/how-to-custom-uisearchbar) –