UITableView one sided Border color?

后端 未结 2 1932
逝去的感伤
逝去的感伤 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条回答
  •  -上瘾入骨i
    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;
    }
    

提交回复
热议问题