iphone - Using drawInRect inside a c method not working -
i have code, draw text inside (so far) simple button:
uiimage *buttonimage(cgrect bounds, uicolor *fillcolor, nsstring *title) { uigraphicsbeginimagecontextwithoptions(bounds.size, no, 0); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolorwithcolor(context, fillcolor.cgcolor); cgcontextfillrect(context, bounds); uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); cgcontextsetfillcolorwithcolor(context, [uicolor whitecolor].cgcolor); [title drawinrect:bounds withfont:panelbuttonfont]; uigraphicsendimagecontext(); return image; } the problematic part drawinrect. it's not drawing text. font correct, , i've tested normal font code there, it's not that. think perhaps doesn't realise want draw onto image it's producing?
just change order , image after draw text:
uiimage *buttonimage(cgrect bounds, uicolor *fillcolor, nsstring *title) { uigraphicsbeginimagecontextwithoptions(bounds.size, no, 0); cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetfillcolorwithcolor(context, fillcolor.cgcolor); cgcontextfillrect(context, bounds); cgcontextsetfillcolorwithcolor(context, [uicolor whitecolor].cgcolor); [title drawinrect:bounds withfont:panelbuttonfont]; uiimage *image = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); return image; }
Comments
Post a Comment