iOS去掉UISearchBar的灰色背景框
来源:互联网 发布:网络三大奇书之一 编辑:程序博客网 时间:2024/05/16 19:55
在使用那个UISearchBar的时候我个人觉得那个灰色背景框和背景很不搭。结果设置背景为无色,但是设置完了还是不行。然后我去网上看了一下,看到有两种解决的方法。
1.设置barTinColor和背景相同就看不出来那个灰色框了。因为肉眼看不出来所以这是一个障眼法。不建议大家使用哈。当然你要是觉得其他方法麻烦呢用这个还是可以的啦。
2.至于这种呢就取巧于那个subviews的方法了。这个方法跟我们的版本有关的,所以最先得判断版本了。iOS7.0以上有两层的subviews,以下有一层。刚刚好7.0呢就没有你可以直接设置背景颜色和那个barTinColor味无色就好了。接下来看代码
有两种写法。
(1) float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if (version == 7.0) { _searchBar.backgroundColor = [UIColor clearColor]; _searchBar.barTintColor = [UIColor clearColor]; }else{ for(int i = 0 ;i < _searchBar.subviews.count;i++){ UIView * backView = _searchBar.subviews[i]; if ([backView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES) { [backView removeFromSuperview]; [_searchBar setBackgroundColor:[UIColor clearColor]]; break; }else{ NSArray * arr = _searchBar.subviews[i].subviews; for(int j = 0;j<arr.count;j++ ){ UIView * barView = arr[i]; if ([barView isKindOfClass:NSClassFromString(@"UISearchBarBackground")] == YES) { [barView removeFromSuperview]; [_searchBar setBackgroundColor:[UIColor clearColor]]; break; } } } } }
(2)// 去掉UISearchBar的那个灰色背景框 float version = [[[UIDevice currentDevice] systemVersion] floatValue]; if ([self.searchController.searchBar respondsToSelector:@selector(barTintColor)]) { float iosversion7_1 = 7.1; if (version >= iosversion7_1){ [[[[self.searchController.searchBar.subviews objectAtIndex:0] subviews] objectAtIndex:0] removeFromSuperview]; [self.searchController.searchBar setBackgroundColor:[UIColor clearColor]]; }else { //iOS7.0 [self.searchController.searchBar setBarTintColor:[UIColor clearColor]]; [self.searchController.searchBar setBackgroundColor:[UIColor clearColor]]; } }else { //iOS7.0以下 [[self.searchController.searchBar.subviews objectAtIndex:0] removeFromSuperview]; [self.searchController.searchBar setBackgroundColor:[UIColor clearColor]]; } // 禁止搜索栏上移 self.searchController.hidesNavigationBarDuringPresentation = NO;
0 0
- iOS去掉UISearchBar的灰色背景框
- 去掉UISearchBar的那个灰色背景框,,
- 去掉UISearchBar的那个灰色背景框
- iOS UISearchBar去掉灰色部分
- iOS 通过设置颜色去除UISearchBar的灰色背景
- UISearchBar 去掉灰色边框
- 如何去掉UISearchBar背景框?
- iOS UISearchBar的背景框颜色适应
- 如何去除UISearchBar默认的灰色背景颜色
- UISearchBar背景透明,去掉背景,自定义背景
- UISearchBar背景透明,去掉背景,自定义背景
- UIsearchBar背景透明,去掉背景,自定义背景
- UISearchBar背景透明,去掉背景,自定义背景
- UISearchBar背景透明,去掉背景,自定义背景
- UISearchBar背景透明,去掉背景,自定义背景
- UISearchBar背景透明,去掉背景,自定义背景
- UISearchBar背景透明,去掉背景,自定义背景
- UISearchBar会有灰色背景一闪
- VS运行程序一闪而过
- hdu 3002 全局最小割模板题
- Apache POI实现EXcel的数据导入数据库
- RabbitMQ基础概念详解
- memset和指针new一起使用时请小心
- iOS去掉UISearchBar的灰色背景框
- FineUIMvc随笔(4)自定义回发参数与自定义回发
- leetcode [Length of Last Word]
- 洛谷P3301 [SDOI2013]方程
- java2ee
- jQuery源码分析-02正则表达式-RegExp-常用正则表达式
- poj 3280 (DP)
- 82:Binary Tree Maximum Path Sum
- 如何上传图片到github并在README.MD文件中显示