开发者

UISearchBar remove background on iOS 4.1

开发者 https://www.devze.com 2023-04-06 08:26 出处:网络
I\'m trying to remove the background of UISearchBar to make it transparent. I tried these solutions: 1.

I'm trying to remove the background of UISearchBar to make it transparent. I tried these solutions:

1.

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

2.

[[searchBar.subviews objectAtIndex:0] rem开发者_开发知识库oveFromSuperview];

These two methods both work on iOS 4.3, but not on 4.1. it shows black. How can I make it work on iOS 4.1? I'm using SDK 4.3. Thanks.


This should work:

[[searchBar.subviews objectAtIndex:0] removeFromSuperview];
[searchBar setBackgroundColor:[UIColor clearColor]];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号