在UIScrollview上画一条线

时间:2013-07-15 12:30:57

标签: ios uiscrollview

我正在尝试绘制一条线来指示滚动视图(日程表)上的当前时间。

我认为问题是该路径无效,因为它获取当前视图上下文而不是scrollview内容大小的实际大小。如果我将currentTime float的值设置得更小,它将绘制一条线。

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];

0 个答案:

没有答案
相关问题