分组tableView中的UITableViewSeparator

时间:2012-06-20 18:12:21

标签: iphone uitableview

在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线来获取我的分隔符?或者,还有更好的方法?感谢。

1 个答案:

答案 0 :(得分:1)

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

以下是示例图片:

sample image

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

// 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);