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。 两个缺少任何一个都不行。
说的不对的地方,请大神们指正。不断的总结、提升中~
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。 两个缺少任何一个都不行。
说的不对的地方,请大神们指正。不断的总结、提升中~
相关文章推荐
- 让UITableView的headerView或footerView跟随cell一起滚动
- java中StringBuilder、StringBuffer、String类之间的关系
- 排序检索B - List of Conquests
- iOS开发系列--UITableView全面解析
- hdoj 1509 Windows Message Queue
- iOS开发 -- UIViewContentMode各类型效果
- UIAlertView的基本用法
- 黑马程序员_String类型以及StringBuilder
- POJ 1986 DIstance Query LCA水题
- RequireJS Optimizer 的使用和配置
- Reveal UI 分析工具简单使用
- 【Mockplus教程】安装Mockplus
- 【Mockplus教程】界面闪烁花屏怎么办?
- 【Mockplus教程】MAC 安全提示无法安装怎么办?
- Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
- 【Mockplus教程】为什么 Windows XP 无法安装?
- 【Mockplus视频教程】《10分钟玩转Mockplus》
- IOS UITableView拖动排序功能
- [leetcode] 187.Repeated DNA Sequences
- POJ---2299-Ultra-QuickSort