ios - ObjectiveC UIBezierPath path close issue -
i try hexagon , have issue in close path.
here hexagon, , close path not smooth.
here drawing code
cashapelayer* shapelayer = [cashapelayer layer]; uibezierpath* path = [uibezierpath bezierpath]; // [path setlinejoinstyle:kcglinejoinround]; // [path setlinejoinstyle:kcglinejoinbevel]; [path setlinejoinstyle:kcglinejoinmiter]; // cgfloat dashes[] = {6, 2}; // [path setlinedash:dashes count:2 phase:0]; // [path stroke]; cgfloat radians = 100.0; nsinteger num = 6; cgfloat interval = 2*m_pi/num; nsinteger initx = radians*cosf(interval); nsinteger inity = radians*sinf(interval); [path movetopoint:cgpointmake(location.x - semiwidth + initx, location.y - semiheight + inity)]; for(int i=1; i<=num; i++){ cgfloat x = radians*cosf(i*interval); cgfloat y = radians*sinf(i*interval); [path addlinetopoint:cgpointmake(location.x - semiwidth + x, location.y - semiheight + y)]; } [path closepath]; shapelayer.path = [path cgpath]; shapelayer.strokecolor = [[uicolor yellowcolor] cgcolor]; shapelayer.fillcolor = [[uicolor browncolor] cgcolor]; shapelayer.linewidth = 4.0f;
also try use different options following no luck
[path setlinejoinstyle:kcglinejoinround]; [path setlinejoinstyle:kcglinejoinbevel]; [path setlinejoinstyle:kcglinejoinmiter];
the problem you're not making first point (the point move-to) same way you're making other points (the points line-to).
nsinteger initx = radians*cosf(interval); nsinteger inity = radians*sinf(interval); [path movetopoint:cgpointmake( location.x - semiwidth + initx, location.y - semiheight + inity)];
instead, make first point parallel others:
cgfloat x = radians*cosf(0*interval); cgfloat y = radians*sinf(0*interval); [path movetopoint:cgpointmake( location.x - semiwidth + x, location.y - semiheight + y)];
that's same you'll later i*interval
, , emphasize parallelism, i've written 0
0*interval
. here's ended with:
Comments
Post a Comment