UITableView使用方法(三) - 交替颜色单元格的实现
来源:互联网 发布:lol徐老师淘宝店网址 编辑:程序博客网 时间:2024/05/16 00:31
效果如下:
主要是在tableView的cellForRowAtIndexPath中实现,实现代码如下:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *tag=@"tag"; CGSize size; CGFloat actualSize; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tag]; if (cell==nil ) { cell=[[[ UITableViewCell alloc ] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tag] autorelease]; } NSUInteger row=[indexPath row]; //设置文本 cell.textLabel.text = [listData objectAtIndex :row]; //--------------------------------------------------------- //设置颜色交替 if( (row%2) ==0) cell.backgroundColor = [UIColor whiteColor]; else cell.backgroundColor = [UIColor lightGrayColor]; //--------------------------------------------------------- cell.detailTextLabel.text = [listData objectAtIndex :row]; return cell;}
比较简单,就是改变不同行的背景就行了。
运行环境:
MacOS 10.7.4 + XCode 4.3.3 + iOS 5.1
- UITableView使用方法(三) - 交替颜色单元格的实现
- UITableView 颜色交替单元格。
- 动态设置交替单元格颜色
- jQuery实现表格颜色的交替显示
- 实现表格交替颜色
- ios UITableView单元格多选框的实现
- 颜色交替的表格
- 交替颜色的DataGridView
- 交替颜色的DataGridView
- 交替颜色的表格
- jquery交替变换颜色的三种方法 实例代码
- XSL技巧:实现表格中行的交替颜色
- 用jQuery实现表格颜色的交替显示
- 定制UITableView的单元格
- UITableView的“静态单元格”
- ListCtrl设置单个单元格颜色的实现
- ListCtrl设置单个单元格颜色的实现 .
- ListCtrl设置单个单元格颜色的实现
- 20120817-WindowProc回调函数
- vc++ 编程 经典电子书
- 程序员应该具备什么素质
- Ajax,选择同步还是异步
- C# Properties.Settings
- UITableView使用方法(三) - 交替颜色单元格的实现
- 【算法与数据结构】三分查找
- css中height:100%不起作用的解决方法
- 一个N个整数的无序数组,给你一个数sum,求出数组中是否存在两个数,使他们的和为sum
- 工作效率和薪水加倍的7个秘诀
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'sessionFactory' is d
- VC++6.0共享内存技术总结
- Ubuntu下如何解压缩zip,tar,tar.gz,tar.bz2文件
- VC++6.0内存文件映射