UISearchBar的白色区域始终无法去除,也就是清除背景色,或者白色区域可以改变成其他颜色,求解UISearchBar *searchBar = [[UISearchBaralloc] initWithFrame: CGRectMake(15.0f, 30.0f, 145.0f, 45.0f)];
searchBar.placeholder = @"Enter Name";
searchBar.delegate = self;
searchBar.showsCancelButton = NO;
searchBar.showsScopeBar = NO;
searchBar.barStyle = UIBarStyleBlackTranslucent;
searchBar.inputView.backgroundColor = [UIColorclearColor];
searchBar.alpha = 1.0f;
searchBar.backgroundColor = [UIColorclearColor];
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
[[[searchBar subviews] lastObject] setBackgroundColor:[UIColorcolorWithRed:0.118fgreen:0.118fblue:0.118falpha:1.0f]];
searchBar.keyboardType = UIKeyboardTypeDefault;
[self addSubview:searchBar];
self._searchBar = searchBar;
[searchBar release];
searchBar.placeholder = @"Enter Name";
searchBar.delegate = self;
searchBar.showsCancelButton = NO;
searchBar.showsScopeBar = NO;
searchBar.barStyle = UIBarStyleBlackTranslucent;
searchBar.inputView.backgroundColor = [UIColorclearColor];
searchBar.alpha = 1.0f;
searchBar.backgroundColor = [UIColorclearColor];
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
[[[searchBar subviews] lastObject] setBackgroundColor:[UIColorcolorWithRed:0.118fgreen:0.118fblue:0.118falpha:1.0f]];
searchBar.keyboardType = UIKeyboardTypeDefault;
[self addSubview:searchBar];
self._searchBar = searchBar;
[searchBar release];
UIImage *imageBgSearch = [UIImage imageNamed:@"bg_searchBar.png"];
UITextField *a = [[searchBar subviews] objectAtIndex:1];
a.textColor = [UIColor whiteColor];
a.background = imageBgSearch;
//(UITextField *)[[searchBar subviews] objectAtIndex:1].background = [UIImage imageNamed:@"bg_searchBar.png"];
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}