iOS 6/7 UISearchBar的背景色设置

在iOS7中,UISearchBar的子视图变成一个UIView,所以原来的方法不管用了,但是看了一下文档,在iOS7中新增了一个barTintColor的属性,我们可以设置barTintColor为clearColor

float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if ([ searchBar respondsToSelector : @selector (barTintColor)]) { float iosversion7_1 = 7.1 ; if(version >= iosversion7_1) { //iOS7.1 [[[[searchBar.subviews objectAtIndex : 0 ] subviews] objectAtIndex:0] removeFromSuperview]; [ searchBar setBackgroundColor:[ UIColor clearColor]]; } else { //iOS7.0 [ searchBar setBarTintColor:[UIColor clearColor]]; [ searchBar setBackgroundColor:[UIColor clearColor]];
        }
    }

    else

    {
        //iOS7.0 以下
        [[searchBar.subviews objectAtIndex:0] removeFromSuperview ]; [searchBar setBackgroundColor:[UIColor clearColor]];

    }

你可能感兴趣的:(iOS 6/7 UISearchBar的背景色设置)