我有一个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上实现UITableViewCell的。
不过,我仍然想知道如何在iOS 7中对单元格进行自定义绘图。
发布于 2013-09-26 12:28:55
尝试将背景色属性设置为透明颜色。
self.backgroundColor = [UIColor clearColor]发布于 2013-09-26 12:19:11
必须使用drawRect创建子视图,并将其放到UITableViewCell中。
https://stackoverflow.com/questions/18884327
复制相似问题