UITableViewCell自定义CG绘图iOS 7

我有一个UITableViewCell子类与以下drawRect:实现。 它将在单元格的底部画一条线,缩进30点以符合我们的devise。 tableView.separatorStyle被设置为UITableViewSeparatorStyleNone来代替这个自定义绘图。

 - (void)drawRect:(CGRect)rect { [super drawRect:rect]; if (!_hideBottomLine) { CGContextRef ref = UIGraphicsGetCurrentContext(); CGContextSetShouldAntialias(ref, NO); CGContextSetStrokeColorWithColor(ref, [UIColor colorWithWhite:0.75 alpha:1].CGColor); CGContextSetLineWidth(ref, 1); CGContextMoveToPoint(ref, 30, CGRectGetMaxY(rect)); CGContextAddLineToPoint(ref, CGRectGetMaxX(rect), CGRectGetMaxY(rect)); CGContextStrokePath(ref); } } 

在iOS 6 SDK和iOS 6 SDK中构build时,这在iOS 6和iOS 7中运行良好。 现在我正在使用iOS 7 SDK进行构build,不会出现这一行。

我在iOS 7 SDK中错过了一些CG绘图的改变吗?

编辑:

所以我现在意识到有更好的方法来在iOS 7中使用cell.separatorInset来做到这cell.separatorInset ,我也发现了一些其他类似的CG代码,我写的工作。 所以我认为这个问题是孤立的实施drawRect:UITableViewCell

我仍然喜欢如何在iOS 7上的单元格自定义绘图的答案。

尝试将背景颜色属性设置为透明颜色

 self.backgroundColor = [UIColor clearColor] 

您必须使用drawRect创build子视图并将其放到您的UITableViewCell中

看这里不能在UITableViewCell的drawRect中绘制