UITableViewCell自定义CG绘图iOS 7 [英] UITableViewCell custom CG drawing iOS 7

查看:116
本文介绍了UITableViewCell自定义CG绘图iOS 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableViewCell 子类,其中包含以下 drawRect:实现。它将在单元格的底部绘制一条线,缩进30个点以匹配我们的设计。 tableView.separatorStyle 设置为 UITableViewSeparatorStyleNone 代替此自定义绘图。

I have a UITableViewCell subclass with the following drawRect: implementation. It will draw a line at the bottom of the cell, indented by 30 points to match our design. The tableView.separatorStyle is set to UITableViewSeparatorStyleNone in lieu of this custom drawing.

- (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和iOS 7上运行良好使用iOS 6 SDK构建。现在,我正在使用iOS 7 SDK进行构建,但该行不会出现。

This worked great in iOS 6 and on iOS 7 when built with the iOS 6 SDK. Now that I am building with the iOS 7 SDK the line does not appear.

我是否错过了iOS 7 SDK中CG绘图的一些变化?

Am I missing some change with CG drawing in the iOS 7 SDK?

编辑:

所以我现在意识到在iOS 7中有一种更好的方法可以使用 cell.separatorInset ,我还发现了一些我写过的其他类似的CG代码。所以我认为这个问题与在 UITableViewCell上实现 drawRect:是分开的

So I now realize there is a better way to do this in iOS 7 using cell.separatorInset, I also found some other similar CG code I had written that works. So I think the issue is isolated to implementing drawRect: on UITableViewCell

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

I'd still like an answer on how to do custom drawing on the cell in iOS 7 though.

推荐答案

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

Try set background color property to transparent color

self.backgroundColor = [UIColor clearColor]

这篇关于UITableViewCell自定义CG绘图iOS 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆