我正在尝试画一条线来指示滚动视图(日程表)上的当前时间。
我认为问题在于路径无效,因为它采用当前视图上下文而不是滚动视图内容大小的实际大小。如果我让 currentTime 浮点值更小,它会画一条线。
float currentTime = ([components hour] * 60) + [components minute];
UIGraphicsBeginImageContextWithOptions(self.scrollView.contentSize,NO,0.0);
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, currentTime, self.scrollView.frame.size.width, currentTime)];
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
[shapeLayer setFrame:self.scrollView.frame];
[shapeLayer setPath:[path CGPath]];
[shapeLayer setStrokeColor:[[UIColor redColor] CGColor]];
[shapeLayer setMasksToBounds:YES];
[self.scrollView.layer addSublayer:shapeLayer];