我想要我的UISearchBar 的颜色和背景颜色一样,看不出来是衔接。但是现在的效果就是这样:
我希望是这样的,就是和背景融为一体的:
用这个代码:
UITextField *searchField = [self.searchBar valueForKey:@"_searchField"];
[searchField setBackground:[UIImage imageNamed:@"searchfield_bg"]];
[self.searchBar setTintColor:[UIColor blackColor]];
UIImage *searchimg = [UIImage imageNamed:@"search_panel.png"];
for (UIView *subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
UIView *bg = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:searchimg];
[self.searchBar insertSubview:bg aboveSubview:subview];
[subview removeFromSuperview];
[bg release];
break;
}
}
我是用这个代码实现了这样的效果:你只要改一下颜色就行了。
最终效果是这样的