ios - Why does this not dot the line correctly? -
cgcontextref currentcontext = uigraphicsgetcurrentcontext(); cgcontextsetstrokecolorwithcolor(currentcontext, hh2darkgray.cgcolor); cgfloat lengths[] = {0, 8}; cgcontextsetlinecap(currentcontext, kcglinecapround); cgcontextsetlinewidth(currentcontext, 1); cgcontextsetlinedash(currentcontext, 0.0f, lengths, 2); cgcontextbeginpath(currentcontext); cgcontextmovetopoint(currentcontext, x1, y1); cgcontextaddlinetopoint(currentcontext, x2, y2); cgcontextclosepath(currentcontext); cgcontextdrawpath(currentcontext, kcgpathstroke);
what doing wrong in above code makes dots not evenly spaced? looks this.
. .. .. .. .. .. .. .. .. .. . when need . . . . . . . . . . . . . . .
i lost , other posts can find don't point out kind of issue. please help?
the problem you're closing path – implicitly draws line first point. if path consists of straight line between 2 points, 2 lines drawn directly on top of each other, causes additional dots appear (those second line offset in dash pattern).
solution: remove call cgcontextclosepath
.
it more logical use {1, 8}
instead of {0, 8}
dash pattern, since want 1 point drawn, in practice, doesn't seem make difference.
Comments
Post a Comment