UITableView one sided Border color?

后端 未结 2 1933
逝去的感伤
逝去的感伤 2021-01-03 16:20

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

Any ideas?

相关标签:
2条回答
  • 2021-01-03 16:44

    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;
    }
    
    0 讨论(0)
  • 2021-01-03 17:10

    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!

    0 讨论(0)
提交回复
热议问题