UIScrollViewがあり、UIScrollViewcontentHeightの高さの垂直線を描画したいと思います。パフォーマンスを犠牲にすることなく、これを簡単に行うにはどうすればよいですか?高さが非常に大きいUIVIewを使用して(scrollViewのcontentHeightがわからないため)、UIScrollViewのサブビューとして追加することを考えています。これよりも良いアプローチはありますか?
線は基本的に10px幅、灰色で、scrollViewの上部から下部にまたがっています。
これが私が今持っているものです、私は基本的にUIScrollViewdrawRectをオーバーライドしています:
- (void)drawRect:(CGRect)rect
{
if (shouldDrawVerticalLineForProfile){
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef separatorColor = [UIColor colorWithRed:47.0/255.0 green:47.0/255.0
blue:47.0/255.0 alpha:1.0].CGColor;
// Add at bottom
CGPoint startPoint = CGPointMake(30, 0);
CGPoint endPoint = CGPointMake(30, 10000);
CGContextSaveGState(context);
CGContextSetLineCap(context, kCGLineCapSquare);
CGContextSetStrokeColorWithColor(context, separatorColor);
CGContextSetLineWidth(context, 5.0);
CGContextMoveToPoint(context, startPoint.x + 0.5, startPoint.y + 0.5);
CGContextAddLineToPoint(context, endPoint.x + 0.5, endPoint.y + 0.5);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
}