1

I'm currently writing an App which uses different selection Colors in a grouped Table View. This works great as far as it comes to Borders. I'm able to change Selection Color with the Code in this Post: How to customize the background/border colors of a grouped table view cell?

BUT I'd like to additionally have the nice Border around the Cells that Apple uses. How can I use this Border?

http://www.mediafire.com/?x2gxbkjqu4d2zto

This is the Code to create the Background - mostly copied from above Post: http://www.mediafire.com/?kltwlni1mf4t7ks

And this is how I use it:

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];

As you can see I nearly got it working correctly except of the gray Border around the second Cell.

Community
  • 1
  • 1
sensslen
  • 780
  • 8
  • 17

2 Answers2

2

in cellForRowAtIndexPath you can set the Borders (Separator) for each row/section.

 if(indexPath.row == 1)
    [tableView setSeparatorColor:[UIColor redColor]];

 if(indexPath.section == 2)
    [tableView setSeparatorColor:[UIColor greenColor]];

Just remember to set/reset this for each row/section you want it.

If you want to add the gray border around your red cell it would be

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]];
}

You actually need to use this in your cellForRowAtIndexPath or you're going to set the border for your whole TableView (maybe thats what you want to do)

muffe
  • 2,285
  • 1
  • 19
  • 23
  • Well I guess this is used for normal TableViews, but not for grouped Style TableViewCells.. Unfortunately that doesn't work... – sensslen Mar 07 '12 at 14:06
  • I'm using it the same way in my grouped TableViews. Show some code and I'll try to help – muffe Mar 07 '12 at 14:10
  • Well Then I'm missing something else... I uploaded the Code. Thanks for your Help – sensslen Mar 07 '12 at 14:26
  • Thanks! as you can see in the comment on my Question I managed to draw this border. I'm not sure wether your Solution works, because I'm changing the Background View and a quick try did not change anything. Nevertheless thanks for answering. – sensslen Mar 07 '12 at 15:51
0

I found a Solution to this. it is not totally the same (as UITableviewCell in grouped Style got a even more sophisticated Design in iOS5 but this is sufficient to me. I borrowed this Approach from http://cocoawithlove.com/2010/12/uitableview-construction-drawing-and.html

and it works great!

The code I used is: http://www.mediafire.com/?mdxkpfe8g74ctk9

Hope this helps others

sensslen
  • 780
  • 8
  • 17
  • Unfortunately you're right - It's quite a bit since I uploaded them.... Unfortunately I don't have them lying around anymore. I switched to a new approach with totally custom designed images and use setBackgroundView function of UITableviewcell in order to set the view! – sensslen Sep 23 '13 at 10:38