SearchBar、Tableview右边的英文A-Z背景色设置为任意颜色
来源:互联网 发布:demo软件 编辑:程序博客网 时间:2024/04/28 18:33
首先来一张效果图 如下
1、去掉UISearchBar的背景色代码如下
_searchbar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, navHeight, SCREEN_WIDTH, 40)]; _searchbar.backgroundColor = [RGB(244, 244, 244)colorWithAlphaComponent:.2f]; _searchbar.barStyle = UIBarStyleBlackTranslucent; _searchbar.barTintColor = [RGB(244, 244, 244)colorWithAlphaComponent:.2f]; _searchbar.tintColor = [RGB(244, 244, 244)colorWithAlphaComponent:.2f]; _searchbar.autocorrectionType = UITextAutocorrectionTypeNo; _searchbar.autocapitalizationType = UITextAutocapitalizationTypeNone; _searchbar.placeholder = (@"Search"); _searchbar.delegate = self; _searchbar.backgroundImage = [self imageWithColor:[UIColor clearColor] size:_searchbar.bounds.size]; for (UIView *subview in _searchbar.subviews){ if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) { [subview removeFromSuperview]; break; } } [self.view addSubview:_searchbar];
上面初始化代码可自行删减 设置背景色主要是imageWithColor方法
//取消searchbar背景色- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size{ CGRect rect = CGRectMake(0, 0, size.width, size.height); UIGraphicsBeginImageContext(rect.size); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(context, [color CGColor]); CGContextFillRect(context, rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image;}
2、去掉TableView右边英文字母的背景色(系统默认为白色)
_mainTBV = [[UITableView alloc]initWithFrame:CGRectMake(0, _searchbar.bottom, SCREEN_WIDTH, SCREEN_HEIGHT-_searchbar.bottom)]; _mainTBV.dataSource = self; _mainTBV.delegate = self; _mainTBV.backgroundColor = [UIColor clearColor]; _mainTBV.separatorStyle = UITableViewCellSeparatorStyleNone; [_mainTBV setAllowsMultipleSelection:YES]; _mainTBV.bounces = NO; _mainTBV.sectionIndexBackgroundColor = [UIColor clearColor]; [self.view addSubview:_mainTBV];
sectionIndexBackgroundColor 就是设置TableView的背景色 我这设置成无色
阅读全文
0 0
- SearchBar、Tableview右边的英文A-Z背景色设置为任意颜色
- android studio设置黑色背景色和右边颜色条
- zendstiduo背景色设置为保护眼睛的颜色》》》
- 设置tableview选中行的背景色
- Windows 界面:OnCustomDraw 设置 CListCtrol 任意行的文本字体颜色以及背景色
- 修改SearchBar field的背景色
- 设置按钮的背景色和颜色
- 设置UILabel的背景色为透明
- iOS7,修改SearchBar背景色
- 为元素设置背景色
- 为文本设置背景色
- 设置图片为背景色
- 为eclipse设置背景色
- miniUI改变行的背景色,设置行的颜色
- 如何设置对话框、控件的背景色、文字颜色
- 设置button按钮背景色,及字体的颜色
- DataGrid中行背景色和字体颜色的设置
- 如何设置richedit的默认背景色和文字颜色
- Maven多模块项目介绍和搭建
- 【hdu2929】【高精度+动规】CQYZ_Vijos_P2102 越大越好
- 埃拉托斯特尼筛法算法复杂度(n*lnlnn)的证明([欧拉数学]素数倒数之和)
- 四位计算机的原理及其实现
- Android px适配生成Px文件
- SearchBar、Tableview右边的英文A-Z背景色设置为任意颜色
- 记第一次成功的逆向(ctf)
- UVA
- Topological Sort(25 分)
- 高精度板子
- .NET Framework 3.5 无法安装以下功能 安装错误:0x800F0906
- 图片压缩按比例压缩
- 成绩转换
- 链表相关的算法题大汇总 — 数据结构之链表奇思妙想