您的位置:首页 > 产品设计 > UI/UE

UITableViewCell drawRect画线在iOS7下不显示的问题

2015-08-18 16:10 495 查看
- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, kWhite_Color.CGColor);

CGContextFillRect(context, rect);

UIColor *lineColor = HexColor(@"#DBD8D8");

CGFloat lineHeight = LLISIOS8 ? 1/[UIScreen mainScreen].scale : 1;

CGContextSetStrokeColorWithColor(context, lineColor.CGColor);// 线条颜色

CGContextSetLineWidth(context, lineHeight);//线条宽度

CGContextMoveToPoint(context, 0,rect.size.height - lineHeight); //开始画线, x,y 为开始点的坐标

CGContextAddLineToPoint(context, rect.size.width, rect.size.height - lineHeight);//画直线, x,y 为线条结束点的坐标

CGContextStrokePath(context); //开始画线

}
这个是在cell 里面画线的代码,在iOS8上面运行一直没有问题,但同事用他iPhone4s iOS7下测试的时候,cell的线条突然消失了。
Google 了一下,发现cell 在iOS7下 backgroundColor 是白色不透明的,iOS8下 是clearColor 。所以在iOS7下画线 会被遮住。
解决的方法:
1、直接设置 [self.subviews[0] setBackgroundColor:kClear_Color] 。通过控制台输出这是个cell.subviews 既然是UITableViewCellScrollView 类型的view,跟我想象的输出contentView有些出入,暂时没理清楚这两者的层次关系.后面搞清楚了在补上
<__NSArrayM 0x7c68dea0>(
<UITableViewCellScrollView: 0x7c690fa0; frame = (0 0; 280 63); autoresize = W+H; gestureRecognizers = <NSArray: 0x7c691230>; layer = <CALayer: 0x7c691170>; contentOffset: {0, 0}>
)
2、self.backgroundColor 、self.contentView.backgroundColor 为 clearColor。 两个缺少任何一个都不行。
说的不对的地方,请大神们指正。不断的总结、提升中~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: