Draw dotted (not dashed!) line, with IBDesignable in 2017

前端 未结 10 1712
死守一世寂寞
死守一世寂寞 2020-11-28 03:25

It\'s easy to draw a dashed line with UIKit. So:

CGFloat dashes[] = {4, 2};
[path setLineDash:dashes count:2 phase:0];
[path stroke];
         


        
10条回答
  •  醉话见心
    2020-11-28 04:18

    Objective-C version of the Swift example above:

    UIBezierPath * path = [[UIBezierPath alloc] init];
    [path moveToPoint:CGPointMake(10.0, 10.0)];
    [path addLineToPoint:CGPointMake(290.0, 10.0)];
    [path setLineWidth:8.0];
    CGFloat dashes[] = { path.lineWidth, path.lineWidth * 2 };
    [path setLineDash:dashes count:2 phase:0];
    [path setLineCapStyle:kCGLineCapRound];
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(300, 20), false, 2);
    [path stroke];
    UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

提交回复
热议问题