无法在UITableViewCell的drawRect中绘制 [英] Can't draw in UITableViewCell's drawRect
问题描述
我在使用自定义UITableViewCell的drawRect方法时遇到问题。这是我正在使用的代码
I'm having trouble drawing in the drawRect method of my custom UITableViewCell. Here is the code I am using
- (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);
}
我已经调试以确保所有数值都有意义看来他们这样做了。无法真正找出屏幕上没有任何内容的原因。
I've debugged to make sure that all of the numeric values make sense and it appears that they do. Can't really find out why nothing is being drawn on screen.
这也是一个在笔尖中定义的单元格。我正在使用iOS 7 sdk构建。
For what its worth, this is a cell defined in a nib as well. And i'm building with the iOS 7 sdk.
任何想法?
tahnks
推荐答案
你可能不应该在UITableViewCell自己的drawRect中这样做。相反,创建一个自定义UIView并将其添加为子视图。
You probably shouldn't do this in UITableViewCell's own drawRect. Instead, create a custom UIView and add it as a subview.
另请参阅这个答案。
这篇关于无法在UITableViewCell的drawRect中绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!