Ios Can';t在UITableViewCell中绘制';s drawRect
我在自定义UITableViewCell的drawRect方法中绘图时遇到问题。这是我正在使用的代码Ios Can';t在UITableViewCell中绘制';s drawRect,ios,objective-c,uitableview,core-graphics,Ios,Objective C,Uitableview,Core Graphics,我在自定义UITableViewCell的drawRect方法中绘图时遇到问题。这是我正在使用的代码 - (void)drawRect:(CGRect)rect { CGContextRef ctx = UIGraphicsGetCurrentContext(); CGPoint origin = _faceView.frame.origin; CGFloat width = _faceView.frame.size.width; CGFloat
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGPoint origin = _faceView.frame.origin;
CGFloat width = _faceView.frame.size.width;
CGFloat height = _faceView.frame.size.height;
CGFloat border = 2.0f;
CGPoint startPt = CGPointMake(origin.x + width/2, self.frame.size.height);
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, startPt.x, startPt.y);
CGPoint basePt = CGPointMake(startPt.x, origin.y - height - border);
CGContextAddLineToPoint(ctx, basePt.x, basePt.y);
CGRect circleRect = CGRectMake(origin.x - border, origin.y - border, width + 2 * border, height + 2 * border);
CGContextAddEllipseInRect(ctx, circleRect);
UIColor *color = [UIColor redColor];
CGContextSetFillColorWithColor(ctx, color.CGColor);
CGContextSetStrokeColorWithColor(ctx, color.CGColor);
CGContextSetLineWidth(ctx, 1.0f);
CGContextDrawPath(ctx, kCGPathFillStroke);
}
我已经进行了调试,以确保所有的数值都有意义,而且看起来它们都有意义。我真的不知道为什么屏幕上什么都没画
无论如何,这也是nib中定义的单元格。我正在使用iOS7SDK构建
有什么想法吗
tahnks您可能不应该在UITableViewCell自己的drawRect中执行此操作。相反,创建自定义UIView并将其添加为子视图
另请参见。尝试将BackgroundColor属性设置为透明色
self.backgroundColor = [UIColor clearColor]
你必须把它设置好
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
.....
[cell setNeedsDisplay];
return cell;
}
尝试将
contentView
属性的backgroundColor
设置为清除颜色
self.contentView = [UIColor clearColor];
我同意。除非需要,否则尽量不要使用drawRect方法,因为它会影响运行的性能。谢谢您的好心先生!给我省了很多麻烦