ios - UITableViewCell自定义CG画iOS 7

标签 ios uitableview core-graphics ios7

我有一个 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/

相关文章:

ios - 使用 xib 和自动布局的自定义 UITableViewCell 无法在顶部的多个单元格中正确显示

iphone - 不想将内容集中在 UITableViewCell

ios - QCAR::Image 到 UIImage - CoreGraphics 并保留崩溃

objective-c - 如何从 CGContextRef 获取 UIImage?

ios - 如何在 objective-c 中的单个 View Controller 上加载多个 UIView

ios - swift : Player audio file from another class file

ios - 出队时如何阻止 `UIWebView` 中的 `UITableViewCell` 重新加载?

ios - 如何在 Core Graphics 中绘制任何 PNG 格式

ios - 如何在文本字段中找到 UITextInput 创建的字符串(或长度)? ( swift )

iphone - 串掉字母?