我是iphone的新手,我想更改搜索栏背景以清除颜色,如何将其更改为清除颜色。我的代码是:

UISearchBar *mySearchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(10, 550, 330, 42)];
mySearchBar.delegate = self;
mySearchBar.showsCancelButton = YES;
mySearchBar.placeholder=@"Search here..";
    mySearchBar.tintColor=[UIColor clearColor];
[self.view  addSubview:mySearchBar];


提前致谢:

最佳答案

由于搜索栏具有默认视图,因此我们删除了该视图,因此背景颜色清晰

for (UIView *subview in mySearchBar.subviews) {
    if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
        [subview removeFromSuperview];
        break;
    }
}  

10-08 05:55