搜尋

首頁  >  問答  >  主體

objective-c - 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);
}
巴扎黑巴扎黑2856 天前772

全部回覆(2)我來回復

  • 巴扎黑

    巴扎黑2017-04-17 17:42:46

    程式碼本身沒有問題,可以畫出虛線來

    回覆
    0
  • 怪我咯

    怪我咯2017-04-17 17:42:46

    會不會被別的控制遮住了,打開層級頁面看一下

    回覆
    0
  • 取消回覆