[英]How to Change search bar background color in ipad
I am new in iphone, i want to change the search bar background to clear color how to change it to clear color. 我是iphone的新手,我想更改搜索栏背景以清除颜色,如何将其更改为清除颜色。 My code is:
我的代码是:
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];
Thanks in Advance: 提前致谢:
Because search bar have a default view and we remove this view then background color is clear 由于搜索栏具有默认视图,因此我们删除了该视图,因此背景颜色清晰
for (UIView *subview in mySearchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
in ios 7 i did something like this. 在ios 7中,我做了这样的事情。
if (self.searchDisplayController.searchBar.subviews.count >= 1) {
for (UIView *subview in [[self.searchDisplayController.searchBar.subviews objectAtIndex:0] subviews]) {
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
}
您可以使用色彩设置,请尝试根据您的背景色设置色彩。
mySearchBar.tintColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0];
mySearchBar.backgroundColor = [UIColor clearColor];
不用设置tintColor而是设置搜索栏的backgroundColor。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.