使用自定义颜色和边框创build分组的UITableviewCell
我目前正在编写一个应用程序,它在分组的表视图中使用不同的select颜色。 就边界而言,这个效果很好。 我能够改变select颜色与本文中的代码: 如何自定义分组表格视图单元格的背景/边框颜色?
但是我想另外在苹果公司使用的细胞周围有很好的边框。 我怎样才能使用这个边界?
http://www.mediafire.com/?x2gxbkjqu4d2zto
这是创build背景的代码 – 主要是从上面复制的Post: http : //www.mediafire.com/?kltwlni1mf4t7ks
这就是我如何使用它:
NSIndexPath * indexPath = [[[NSIndexPath alloc] initWithIndex:0] indexPathByAddingIndex:1]; CGRect frame = [[self tableView] rectForRowAtIndexPath:indexPath]; TLCustomCellBackgroundView * selectedBackgroundView = [[TLCustomCellBackgroundView alloc] initWithFrame:frame andColor:[UIColor redColor]]; [selectedBackgroundView setPosition:CustomCellBackgroundViewPositionBottom]; [[[self tableView] cellForRowAtIndexPath:indexPath] setSelectedBackgroundView:selectedBackgroundView];
正如你所看到的,除了第二个单元格周围的灰色边框,我几乎可以正常工作。
在cellForRowAtIndexPath中,您可以为每个行/部分设置边界(分隔符)。
if(indexPath.row == 1) [tableView setSeparatorColor:[UIColor redColor]]; if(indexPath.section == 2) [tableView setSeparatorColor:[UIColor greenColor]];
只要记住为每一个你想要的行/部分设置/重置。
如果你想在你的红细胞周围加上灰色边框,那就是了
if(indexPath.section == 0 && indexPath.row == 1){ //assuming this is the correct index) [tableView.separatorColor = [UIColor colorWithRed:0.67 green:0.67 blue:0.67 alpha:1]; } else { [tableView.separatorColor = [UIColor yourChosenDefaultColor]]; }
你实际上需要在你的cellForRowAtIndexPath中使用它,或者你要为整个TableView设置边界(也许这就是你想要做的)
我find了一个解决scheme。 它不完全相同(因为UITableviewCell分组风格在iOS5中得到了一个更复杂的devise,但这对我来说已经足够了,我借用了http://cocoawithlove.com/2010/12/uitableview-construction-drawing- and.html
而且效果很好!
我使用的代码是: http : //www.mediafire.com/?mdxkpfe8g74ctk9
希望这可以帮助别人