改变section header颜色
来源:互联网 发布:android ui优化 编辑:程序博客网 时间:2024/06/05 06:37
m
本文选自StackOverflow(简称:SOF)精选问答汇总系列文章之一,本系列文章将为读者分享国外最优质的精彩问与答,供读者学习和了解国外最新技术。本文将为读者讲解如何在UITableView里修改section header的颜色?问题:Ilya Suzdalnitski怎样在UITableView里修改section header的颜色?答案:Alex Reynolds希望这个从UITableViewDelegate协议里得到的方法可以对你有所帮助:- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease]; if (section == integerRepresentingYourSectionOfInterest) [headerView setBackgroundColor:[UIColor redColor]]; else [headerView setBackgroundColor:[UIColor clearColor]]; return headerView;}使用任何你喜欢UIColor代替[UIColor redColor]。你可能还希望调整headerView的尺寸。DoctorG这是改变文本颜色的方法:UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width - 10, 18)] autorelease];label.text = @"Section Header Text Here";label.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.75];label.backgroundColor = [UIColor clearColor];[headerView addSubview:label];whyoz不要忘记从委托添加这段代码,否则在某些情况下视图将被切断或者出现在table后面,相对于视图/标签的高度。- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 30;}Leszek ?0?3arna如果你想自定义header颜色,可以这样做:[[UITableViewHeaderFooterView appearance] setTintColor:[UIColor redColor]];这个方法在iOS 6.0.以上都很好用。Maulik这是在标题视图添加图片的方法:- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease]; UIImageView *headerImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top-gery-bar.png"]] autorelease]; headerImage.frame = CGRectMake(0, 0, tableView.bounds.size.width, 30); [headerView addSubview:headerImage]; return headerView;}William Jockusch如果你不想建立自定义视图,你也可以这样改变颜色(需要在iOS6里):-(void) tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { if ([view isKindOfClass: [UITableViewHeaderFooterView class]]) { UITableViewHeaderFooterView* castView = (UITableViewHeaderFooterView*) view; UIView* content = castView.contentView; UIColor* color = [UIColor colorWithWhite:0.85 alpha:1.]; // substitute your color here content.backgroundColor = color; }}Dj S这是常见的问题,我认为答案需要更新一下。这个方法不涉及定义和创建自定义视图。在iOS 6以上,你可以通过以下方法轻松改变背景色和文本色:- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section委托方法例如:- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{ // Background color view.tintColor = [UIColor blackColor]; // Text Color UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; [header.textLabel setTextColor:[UIColor whiteColor]]; // Another way to set the background color // Note: does not preserve gradient effect of original header // header.contentView.backgroundColor = [UIColor blackColor];}orbv通过UITableViewHeaderFooterView设置背景色的方法已经被废弃了。请用contentView.backgroundColor代替。
0 0
- 改变section header颜色
- UITableView 下拉header放大,statusBar改变颜色
- 改变UITableView上section的字体颜色,大小
- ELF Section Header 分析
- 分组:UITableView header 以及section header 用法
- swift -- 更改 tableview section header
- UITableView自定义分割线、改变Header和Footer的背景颜色
- Encountered a section with no Package: header
- 修改UITableView section header title的样式
- UITableView section header 显示在最上面
- Encountered a section with no Package: header
- header+section+footer(底部按钮布局)
- Silverlight改变Header背景色
- 自定义UITableView的header颜色
- table header 颜色的修改
- toolkit:DatePicker header背景颜色
- ionic的header颜色设置
- ionic的header颜色设置
- iOS 几种传值方式(属性,代理,block,通知,本地存储,单例类)附Demo
- JSP复习内容
- 设计模式之模板方法
- DevExpress中chartControl中实现统计图功能
- Binder学习一——Binder基础数据结构
- 改变section header颜色
- 黑马程序员----OC学习笔记之NSArray
- openwrt 下载地址 怕忘了 记之
- erlang 列表推导完全理解
- 【Leetcode Algorithm】Remove Duplicates from Sorted Array
- ORA-16047: DGID mismatch between destination setting and standby
- 于是我开始选择学习软件了,找了一堆的视频,一堆书。晚上下了班就看
- ZooKeeper的事务日志可视化
- [leetcode-73]Set Matrix Zeroes(C语言)