3

私はまっすぐな破線を描こうとしています。ダッシュを描画するように取得しましたが、この黒い背景色が残ります。他の質問に対する多くの回答があるようですが、どれもうまくいきませんでした。

Apple のドキュメントは、塗りつぶしの色を示しており、CGContextFillPath または CGContextDrawPath のいずれかを使用しているようですが、どちらも機能せず、破線の背景はまだ黒です。

- (void)drawRect:(CGRect)rect {
    CGContextRef contextRef = UIGraphicsGetCurrentContext();

    GLFloat lines[] = {self.frame.size.width, self.frame.size.width*2};

    CGFloat grey[4] = {0.6f, 0.6f, 0.6f, 1.0f};
    CGContextSetStrokeColor(contextRef, grey);
    CGContextSetFillColorWithColor(contextRef, [[UIColor clearColor] CGColor]);

    CGContextSetLineDash(contextRef, 0, lines, 2);
    CGContextSetLineWidth(contextRef, self.frame.size.width);

    CGContextBeginPath(contextRef);
    CGContextMoveToPoint(contextRef, 0, 0);
    CGContextAddLineToPoint(contextRef, 0, self.frame.size.height);

    CGContextDrawPath(contextRef, kCGPathFillStroke);
}
4

1 に答える 1