如何在UITableViewCell中绘制一条线

Vel*_*gan 6 iphone

我需要在UITableviewcell中画一条线.

有没有办法做到这一点?

如果有人想知道在UITableview单元格中划线,请回复我.

谢谢.

Mat*_*uch 23

如果线条是水平线或垂直线,您可以添加黑色UIView.像这样.

UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake(0, 25, cell.contentView.bounds.size.width, 1)] autorelease];
lineView.backgroundColor = [UIColor blackColor];
lineView.autoresizingMask = 0x3f;
[cell.contentView addSubview:lineView];
Run Code Online (Sandbox Code Playgroud)

上面的一个用于一条水平线.如果您需要在单元格中间的垂直线,以下代码可以工作

UIView *lineView = [[[UIView alloc] initWithFrame:CGRectMake((cell.contentView.bounds.size.width/2), 0, 1, cell.contentView.bounds.size.height)] autorelease];
Run Code Online (Sandbox Code Playgroud)