开发者

how to change the colors of separators based on section

I am having two section in my table view. I used the setSeparatorColor property to change the color of the separator. It is actually cha开发者_StackOverflownging the color of both the sections. Is it possible to change the separator color based on the section ?


You can accomplish this by adding two one-pixel high subviews just above and below your cell so that they render on top of the UITableView's separator. Here are the specifics:

  1. Create a UITableViewCell subclass with an IBOutlet UIView *topSeparator property and an IBOutlet UIView *bottomSeparator property.

  2. Set your cell.clipsToBounds to NO.

  3. Construct topSeparator with a frame of CGRectMake(0.0f, -1.0f, cell.width, 1.0), and a backgroundColor set to your desired separator color. (Reduce width by 10px on left and right for grouped cells.)

  4. Construct bottomSeparator with a frame of CGRectMake(0.0f, cell.height, cell.width, 1.0), and a backgroundColor set to your desired separator color. (Reduce width by 10px on left and right for grouped cells.)

  5. When returning the first cell in the section, set topSeparator.hidden = YES; bottomSeparator.hidden = NO;.

  6. When returning the last cell in the section, set topSeparator.hidden = NO; bottomSeparator.hidden = YES;.

  7. When returning all other cells in the section, set topSeparator.hidden = NO; bottomSeparator.hidden = NO;

You need separators on both the top and bottom to ensure that one of them renders on top of the UITableView's separator whether you're scrolling up or down.


try to change the seperator color in the method "didSelectRowAtIndexPath"

it will effect at the selection time.

if any dought then leave comment.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜