美文网首页iOS 技术分享
iOS 去掉UISearchBar灰色背景

iOS 去掉UISearchBar灰色背景

作者: Joh蜗牛 | 来源:发表于2017-07-14 16:32 被阅读8次

    有以下两种方法,个人推荐第二种:

    (1)

    floatversion = [[[UIDevicecurrentDevice]systemVersion]floatValue];

    if(version == 7.0) {

    _searchBar.backgroundColor= [UIColorclearColor];

    _searchBar.barTintColor= [UIColorclearColor];

    }else{

    for(inti =  0 ;i <_searchBar.subviews.count;i++){

    UIView* backView =_searchBar.subviews[i];

    if([backViewisKindOfClass:NSClassFromString(@"UISearchBarBackground")] ==YES) {

    [backViewremoveFromSuperview];

    [_searchBarsetBackgroundColor:[UIColorclearColor]];

    break;

    }else{

    NSArray* arr =_searchBar.subviews[i].subviews;

    for(intj = 0;j

    UIView* barView = arr[i];

    if([barViewisKindOfClass:NSClassFromString(@"UISearchBarBackground")] ==YES) {

    [barViewremoveFromSuperview];

    [_searchBarsetBackgroundColor:[UIColorclearColor]];

    break;

    }

    }

    }

    }

    }

    (2)

    floatversion = [[[UIDevicecurrentDevice]systemVersion]floatValue];

    if([_searchBarrespondsToSelector:@selector(barTintColor)]) {

    floatiosversion7_1 = 7.1;

    if(version >= iosversion7_1)        {

    [[[[_searchBar.subviewsobjectAtIndex:0]subviews]objectAtIndex:0]removeFromSuperview];

    [_searchBarsetBackgroundColor:[UIColorclearColor]];

    }

    else{//iOS7.0

    [_searchBarsetBarTintColor:[UIColorclearColor]];

    [_searchBarsetBackgroundColor:[UIColorclearColor]];

    }

    }

    else{

    //iOS7.0以下

    [[_searchBar.subviewsobjectAtIndex:0]removeFromSuperview];

    [_searchBarsetBackgroundColor:[UIColorclearColor]];

    }

    转载自:http://blog.csdn.net/wjh15085872684/article/details/51604558

    相关文章

      网友评论

        本文标题:iOS 去掉UISearchBar灰色背景

        本文链接:https://www.haomeiwen.com/subject/qvhohxtx.html