【问题标题】:UITableViewSeparator in a grouped tableView分组 tableView 中的 UITableViewSeparator
【发布时间】:2012-06-20 18:12:21
【问题描述】:

在 IB 中,

样式:分组,单线蚀刻,白色。 我的视图的背景是清晰的颜色。

在这个 ViewController 的 viewDidLoad 中,我创建了一个虚拟背景视图:

UIView *tableBgView = [[UIView alloc] initWithFrame:self.tableView.frame];
tableBgView.backgroundColor = [UIColor clearColor];
self.tableView.backgroundView = tableBgView;
[tableBgView release];

在 cellForRowAtIndexPath 我有:

    UIView *bgView = [[UIView alloc] initWithFrame:cell.bounds];
    bgView.backgroundColor = [UIColor clearColor];
    cell.backgroundView = bgView;
    [bgView release];

我想要做的是使用矩形背景而不是圆角矩形来查找分组表,因为在我的 cellForRowAtIndexPath 中我创建了一个 clearColor backgroundView 来摆脱圆角矩形外观,所以我不再有分隔符了.我是否只需在此 bgView 底部添加另一个单像素 UIView 行来获取我的分隔符?或者,还有更好的方法?谢谢。

【问题讨论】:

  • 最好的方法是继承 UITableViewCell 并绘制自己的边框。我做到了,稍后我会提供一个示例(我现在在移动设备上)。
  • 我也做了 UITableViewCell 的子类。但是当我把它扔到一个分组的 tableView 中时,它给了我圆角。这就是我将 bgView 添加到单元格的原因。如果你的意思是在我的 UITableViewCell 子类的底部添加一个 1px 的 UIView,那是有道理的。

标签: iphone uitableview


【解决方案1】:

给你,这是我的drawRect:,这将删除圆形单元格。如您所见,这也用于分组表视图控制器中。

这是一个示例图像:

- (void) drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext();

// A left and right margin
float margin = 10.0f;

// Copy the rect and modify it's values to match the margin
CGRect _rect = rect;
_rect.size.width = _rect.size.width - (margin * 2);
_rect.origin.x = margin;

// Fill with a background color, in this case, white.
[[UIColor whiteColor] set];
CGContextFillRect(context, _rect);

// Set a line color
[[UIColor grayColor] set];

// Shift the move point to match our margin
CGContextMoveToPoint(context, margin, _rect.size.height);

// Draw the line with the same width as the cell PLUS the margin (because we shifted it).
CGContextAddLineToPoint(context, _rect.size.width + margin, _rect.size.height);

// Finish
CGContextStrokePath(context);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 2011-06-03
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多