iOS画虚线

想在两个控件之间画虚线,有如下代码,不知为何不能画出来;

- (void)drawRect:(CGRect)rect {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextBeginPath(context);
        CGContextSetLineWidth(context, 5.0);
        CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
        CGFloat lengths[] = {10,10};
        CGContextSetLineDash(context, 0, lengths, 5);
        CGContextMoveToPoint(context, 10.0, 20.0);
        CGContextAddLineToPoint(context, 310.0,20.0);
    //    CGContextMoveToPoint(context, _strategyImageView1.frame.origin.x + 101, _strategyImageView1.frame.origin.y + 25);
    //    CGContextAddLineToPoint(context, _strategyImageView2.frame.origin.x, _strategyImageView2.frame.origin.y + 25);
        CGContextStrokePath(context);
        CGContextClosePath(context);
}
阅读 3.9k
2 个回答

代码本身没有问题,可以画出虚线来
图片描述

会不会被别的控件遮住了,打开层级页面看一下

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题