2012-06-20 25 views
1

在IB中,UITableViewSeparator在分组桌面中查看

风格:分组,单线蚀刻,颜色为白色。 我认为的背景是清晰的颜色。

在这个视图控制器的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来摆脱圆角的矩形外观,我没有分隔符了。我只是添加另一个单像素的UIView线,这是在这个bgView的底部,让我的分离器回来?或者,还有更好的方法?谢谢。

+0

最好的办法是子类的UITableViewCell,并得出自己的边界。我做到了,稍后我会提供一个例子(我现在在移动设备上)。 – Simon

+0

我也做了子类UITableViewCell。但是当我把它扔在一个分组的tableView中时,它给了我圆角。这就是为什么我将bgView添加到单元格中的原因。如果你的意思是在我的UITableViewCell子类的底部添加一个1px的UIView,这是有道理的。 – Crystal

回答

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

}