draw dotted not dashed line using -'ios,uiview,uikit,cashapelayer'

draw dotted not dashed line  using -'ios,uiview,uikit,cashapelayer'

It's pretty easy to draw a dashed line with UIKit, for example

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

Any way to draw a genuine "dotted line"?

Any ideas?

BTW if you need a DASHED line, to save typing, here's a handy class for a DASHED line...

@interface UIDashedLine : UIView

// Extremely easy way to draw a dashed line:
// Simply place an empty UIView in the storyboard, where you want the line.
// Change the class of the UIView, to UIDashedLine.
// At runtime it will draw a perfect dashed line,
// wherever you placed the view in storyboard.

@implementation UIDashedLine

    CGFloat thickness = 4.0;

    CGContextRef cx = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(cx, thickness);
    CGContextSetStrokeColorWithColor(cx, [UIColor blackColor].CGColor);

    CGFloat ra[] = {4,2};
    CGContextSetLineDash(cx, 0.0, ra, 2); // nb "2" == ra count

    CGContextMoveToPoint(cx, 0,thickness*0.5));
    CGContextAddLineToPoint(cx, self.bounds.size.width, thickness*0.5);



asked Sep 7, 2015 by rajesh
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.