iphone - iOS Draw Rectagle with curved ends -
imagine long rectangle (maybe size 200x20). sides have straight edges. in ios app, easy me draw:
cgcontextfillrect(context, cgrectmake(xloc, yloc, 200, 20));
now if wanted shorter ends (on left , right side of rectangle) curved, rather straight edges. code this?
(note relatively inexperienced cgcontext drawing)
something (untested, beware of bugs!):
- (void)drawrect:(cgrect)rect { cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetstrokecolorwithcolor(context, [[uicolor blackcolor] cgcolor]); cgcontextsetrgbfillcolor(context, 0.0, 0.0, 1.0, 1.0); cgrect rrect = cgrectmake(cgrectgetminx(rect), cgrectgetminy(rect), cgrectgetwidth(rect)-30, cgrectgetheight(rect)-30); cgfloat radius = 0.5f; cgfloat minx = cgrectgetminx(rrect), midx = cgrectgetmidx(rrect), maxx = cgrectgetmaxx(rrect); cgfloat miny = cgrectgetminy(rrect), midy = cgrectgetmidy(rrect), maxy = cgrectgetmaxy(rrect); cgcontextmovetopoint(context, minx, midy); cgcontextaddarctopoint(context, minx, miny, midx, miny, radius); cgcontextaddarctopoint(context, maxx, miny, maxx, midy, radius); cgcontextaddarctopoint(context, maxx, maxy, midx, maxy, radius); cgcontextaddarctopoint(context, minx, maxy, minx, midy, radius); cgcontextclosepath(context); cgcontextdrawpath(context, kcgpathfillstroke); }
Comments
Post a Comment