去掉UISearchBar自带的的边框背景 ,分为ios7后和ios7前的解决方案,代码如下:
UISearchBar* searchbar = [[UISearchBar
alloc]initWithFrame:CGRectMake(5,
0, 310,
50)];
searchbar.tag =
1000;
searchbar.delegate =
self;
[cell
addSubview:searchbar];
for (UIView *view
in searchbar.subviews) {
// for before iOS7.0
if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")])
{
[view
removeFromSuperview];
break;
}
// for later iOS7.0(include)
if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count
> 0) {
[[view.subviews
objectAtIndex:0]
removeFromSuperview];
break;
}
}
时间: 2024-10-08 04:40:47