1

I'd like to have a tableview border styled like this one,only the left side is colored.

example image

Any ideas?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Akash Malhotra
  • 1,106
  • 1
  • 17
  • 30
  • 1
    Many ideas! What is your current approach and what did you have problems with?? – phi Mar 03 '12 at 07:26
  • I tried using CALayer and SetBorderWidth and SetBorderColor but it sets the entire perimeter border. I just want the left side as shown in the billboard app photo. – Akash Malhotra Mar 03 '12 at 07:29
  • add opaque view above tablewview and you'll get it. Also if there no separators between cell, you can add such view to them. – Roman Temchenko Mar 03 '12 at 07:39
  • I edited your post to embed your image, which keeps people from having to chase your links to help you out. – bshirley Mar 03 '12 at 07:56
  • simplest way to achieve the above: change the size (in nib) of the table view to not extent to the edges, add small colored rectangle sized view left of the table view with your pretty color – bshirley Mar 03 '12 at 07:59

2 Answers2

5

The easiest way I can think of is to add a little view in the content view:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        //Just a small view
        UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(X_POS, Y_POS, LINE_WIDTH, CELL_HEIGHT)];
        [lineView setBackgroundColor:[UIColor redColor]];
        [[cell contentView] addSubview:lineView];
        [lineView release];

    }
    return cell;
}
El Developer
  • 3,345
  • 1
  • 21
  • 40
1

A simple way would be to add a UIImageView to your cells that has a small width and the same height with the cell (example). Another approach would be to use an image as a background for each cell, and add this border in the actual graphic that you will use (example). And if you want to make it in a layer level, a good start is this example. I hope that helps!

phi
  • 10,634
  • 6
  • 53
  • 88