シンプルなジグザグ線を描くこのコードがあります。X 軸の初期点は 0 です。問題は、初期点を 20 ポイントオフセットしようとしているのですが、うまくいきません。
CGRectInset と CGRectOffSet の両方を試しましたが、うまくいきませんでした..
これが私のコードです:
- (UIBezierPath *)pathFromDataInRect:(CGRect)rect {
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, CGRectGetMidY(rect))];
[path addLineToPoint:CGPointMake((CGRectGetWidth(rect)/3), CGRectGetMaxY(rect))];
[path addLineToPoint:CGPointMake((CGRectGetWidth(rect)/3)*2, CGRectGetMinY(rect))];
[path addLineToPoint:CGPointMake((CGRectGetWidth(rect)/3)*3, CGRectGetMidY(rect))];
UIColor *startColor = [UIColor redColor];
[startColor setStroke];
[path stroke];
return path;
}
- (CGRect)closingDataRect {
return CGRectMake(0, 150, 200, 100);
}
- (void)drawRect:(CGRect)rect
{
CGRect dataRect = [self closingDataRect];
CGRect dataRectOffset = CGRectOffset(dataRect, 20, 0);
[self pathFromDataInRect:dataRectOffset];
}
最初の写真はコードを実行したときのもので、2 番目の写真は私が望むものです。