本の読んだ内容を実際に視覚的に表現した一種の進行状況バーがあります。このバーは、本が読まれた領域を埋める水平線です。例として、100 ページの本で、ユーザーが 1 ~ 10 ページと 90 ~ 100 ページしか読んでいない場合、プログレス バーの左端に 10% の領域、右端に 10% の領域が色で塗りつぶされて表示されます。 .
私は現在、このコードを使用して、1回の読書セッションで四角形を描画しています:
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect innerRect = CGRectInset(rect, 5, 5);
CGRect ProgressIndicator = CGRectMake(innerRect.origin.x, innerRect.origin.y, 20, innerRect.size.height);
CGContextSetStrokeColorWithColor(context, [[UIColor blueColor] CGColor]);
CGContextSetLineWidth(context, 5);
CGContextMoveToPoint(context, CGRectGetMinX(ProgressIndicator), CGRectGetMinY(ProgressIndicator));
CGContextAddLineToPoint(context, CGRectGetMaxX(ProgressIndicator), CGRectGetMinY(ProgressIndicator));
CGContextAddLineToPoint(context, CGRectGetMaxX(ProgressIndicator), CGRectGetMaxY(ProgressIndicator));
CGContextAddLineToPoint(context, CGRectGetMinX(ProgressIndicator), CGRectGetMaxY(ProgressIndicator));
CGContextClosePath(context);
CGContextStrokePath(context);
CGContextSetFillColorWithColor(context, [[UIColor blueColor]CGColor]);
CGContextFillRect(context, ProgressIndicator);
現在、これは 1 回の読み取りセッション用であり、バーの長方形の「読み取り」部分として 1 つの四角形のみを描画します。バーに描画する複数の四角形 (配列など) がある場合、描画を管理するにはどうすればよいですか。別の四角形を描画すると、現在の描画が失われるのではないかと心配しています。
「for」ループを使用してこれらの複数の四角形を描画するにはどうすればよいですか?
これは非常にばかげた質問かもしれませんが、それを回避する方法を見つけようとしましたが、成功しませんでした。