设置UITableView Section的背景颜色和字体颜色
2012-05-30 11:24
423 查看
section所显示的灰色背景和白色字体是默认的,调用以下方法即可实现
如果想改变此处的背景与字体的话,官方没有开放接口去直接修改以上两个属性,所以,只有自己加Label,加View去实现,代码如下:
实现委托方法- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
需要注意的一点是:这个方法里返回视图的大小是固定不变的
The table view automatically adjusts the height of the section header to accommodate
the returned view object. The table view does not call this method if it was created in a plain style (UITableViewStylePlain).
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { return [self.keys objectAtIndex:section]; }
如果想改变此处的背景与字体的话,官方没有开放接口去直接修改以上两个属性,所以,只有自己加Label,加View去实现,代码如下:
实现委托方法- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView* myView = [[[UIView alloc] init] autorelease]; myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7]; UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)]; titleLabel.textColor=[UIColor whiteColor]; titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.text=[self.keys objectAtIndex:section]; [myView addSubview:titleLabel]; [titleLabel release]; return myView; }
需要注意的一点是:这个方法里返回视图的大小是固定不变的
The table view automatically adjusts the height of the section header to accommodate
the returned view object. The table view does not call this method if it was created in a plain style (UITableViewStylePlain).
相关文章推荐
- IOS_设置UITableView Section的背景颜色和字体颜色(自定义section布局)
- 设置UITableView Section的背景颜色和字体颜色-自定义Section
- 设置UITableView Section的背景颜色和字体颜色 ----------自
- 设置UITableView Section的背景颜色和字体颜色
- ios6及以下设置uitableview背景颜色
- ios:改变tableview的titleForHeaderInSection字体颜色设置
- UITableView设置快速索引字体颜色
- iOS中通过设置CSS改变WebView字体大小,颜色,背景颜色
- UITableView背景颜色设置
- 通过选择器selector给TextView,Button设置字体颜色和背景颜色
- 关于UItableView的表头背景颜色的设置
- UITableView Grouped风格时,设置背景颜色的问题
- 1016-06-首页20-封装工具条---UITableView控件距离顶部的间距问题----cell选中时的背景颜色设置
- 关于SearchView设置字体颜色,提示字体及背景的解决方法
- ios 设置UITableView 选中行cell的背景颜色(自定义选中的背景颜色)
- WebView设置字体颜色, 字体大小,背景
- TextView设置超链接、背景颜色、字体颜色等等,Spannable的使用。
- tablewidget 和tableview items row column 玩转 合并 背景 字体 颜色 大小设置
- UICollectionView 设置不同的 Section 背景颜色
- WebView设置字体颜色, 字体大小,背景