我有一个 UITableViewCell
子类,其中包含以下 drawRect:
实现。它将在单元格底部绘制一条线,缩进 30 点以匹配我们的设计。 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 和 iOS 7 上运行良好。现在我正在使用 iOS 7 SDK 进行构建,该行不会出现。
我是否遗漏了 iOS 7 SDK 中 CG 绘图的一些变化?
编辑:
所以我现在意识到在 iOS 7 中使用 cell.separatorInset
有更好的方法来执行此操作,我还发现我编写的其他一些类似的 CG 代码有效。所以我认为这个问题与在 UITableViewCell
drawRect:
无关
不过,我仍然想要一个关于如何在 iOS 7 中的单元格上进行自定义绘图的答案。
最佳答案
尝试将背景色属性设置为透明色
self.backgroundColor = [UIColor clearColor]
关于ios - UITableViewCell自定义CG画iOS 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18884327/