UISearchBar去除背景颜色

UISearchBar *searchBar=[[UISearchBar alloc]initWithFrame:frame];
    //这个设置背景透明可能无效
    searchBar.backgroundColor=[UIColor clearColor];
    
    //可采用如下方法去除搜索框背景
    for (UIView *view in searchBar.subviews) {
        // iOS7.0之前
        if ([view isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
            [view removeFromSuperview];
            break;
        }
        // iOS7.0+
        if ([view isKindOfClass:NSClassFromString(@"UIView")] && view.subviews.count > 0) {
            [[view.subviews objectAtIndex:0] removeFromSuperview];
            break;
        }
    }

  

posted @ 2015-08-09 21:47  张小三、  阅读(516)  评论(0编辑  收藏  举报