7

カスタム UITableViewCell の drawRect メソッドでの描画に問題があります。これが私が使用しているコードです

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

すべての数値が意味をなしており、意味があるように見えることを確認するためにデバッグしました。画面に何も描かれていない理由が本当にわかりません。

価値があるのは、これもペン先で定義されたセルです。そして、私はiOS 7 SDKで構築しています。

何か案は?

タンク

4

4 に答える 4

15

backgroungcolor プロパティを透明色に設定してみてください

self.backgroundColor = [UIColor clearColor]
于 2013-09-26T12:25:13.760 に答える
3

設定する必要があります

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
       .....
       [cell setNeedsDisplay];
       return cell;
}
于 2014-10-16T08:22:15.733 に答える
-2

色をクリアするプロパティのセットbackgroundColorを試すcontentView

self.contentView = [UIColor clearColor];
于 2016-08-19T03:03:16.780 に答える