UITableViewCell custom CG drawing iOS 7

本小妞迷上赌 提交于 2019-12-12 11:48:57

问题


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);
    }
}

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.

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

EDIT:

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

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


回答1:


Try set background color property to transparent color

self.backgroundColor = [UIColor clearColor]



回答2:


You must create subview with drawRect and put it to your UITableViewCell

look here Can't draw in UITableViewCell's drawRect



来源:https://stackoverflow.com/questions/18884327/uitableviewcell-custom-cg-drawing-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!