【问题标题】:UITableView one sided Border color?UITableView 一侧的边框颜色?
【发布时间】:2012-03-21 14:37:14
【问题描述】:

我想要一个像这样样式的 tableview 边框,只有左侧是彩色的。

有什么想法吗?

【问题讨论】:

  • 很多想法!你目前的方法是什么,你有什么问题??
  • 我尝试使用 CALayer 和 SetBorderWidth 和 SetBorderColor 但它设置了整个周边边框。我只想要广告牌应用照片中显示的左侧。
  • 在 tablewview 上方添加不透明视图,你会得到它。此外,如果单元格之间没有分隔符,您可以向它们添加这样的视图。
  • 我编辑了您的帖子以嵌入您的图片,这样人们就不必追逐您的链接来帮助您。
  • 实现上述目的的最简单方法:将表格视图的大小(以笔尖为单位)更改为不延伸到边缘,在表格视图左侧添加带有漂亮颜色的小彩色矩形大小的视图跨度>

标签: iphone ios uitableview colors border


【解决方案1】:

我能想到的最简单的方法是在内容视图中添加一个小视图:

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

【讨论】:

    【解决方案2】:

    一种简单的方法是将UIImageView 添加到具有小宽度和与单元格相同高度的单元格(example)。另一种方法是使用图像作为每个单元格的背景,并将此边框添加到您将使用的实际图形中 (example)。如果你想在层级上制作它,一个好的开始是this example。希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      • 1970-01-01
      相关资源
      最近更新 更多