iphone - Which method to use to display text ?Why? -
when drawing using coregraphics draw string/label have 2 methods
- (cgsize)drawinrect:(cgrect)rect withfont:(uifont *)font linebreakmode:(nslinebreakmode)linebreakmode alignment:(nstextalignment)alignment; eg:
[value drawinrect:cgrectmake(xvalue, rect.origin.y, objlegends.value *singleunitwidth,heightofbar) withfont:[uifont systemfontofsize:10.0f] linebreakmode:nslinebreakbyclipping alignment:nstextalignmentcenter]; and
cg_extern void cgcontextshowtext(cgcontextref c, const char *string, size_t length) cg_available_starting(__mac_10_0, __iphone_2_0); eg
cgcontextsavegstate(context); // tanslate , scale upside-down compensate quartz's inverted coordinate system cgcontextsettextmatrix(context, cgaffinetransformmake(1.0,0.0, 0.0, -1.0, 0.0, 0.0)); cgcontextselectfont(context, "helvetica", 10.0f, kcgencodingmacroman); cgcontextsettextdrawingmode(context, kcgtextfill); cgcontextsettextposition(context, xvalue, rect.size.height-heightoftext); if ([value canbeconvertedtoencoding:nsmacosromanstringencoding]) { cgcontextshowtext(context, [value cstringusingencoding:nsmacosromanstringencoding],5); // strlen([value cstringusingencoding:nsmacosromanstringencoding])); } cgcontextrestoregstate(context); which 1 method , why?
the best method 1 simplest achieve goal. higher level of api can use better. if can use nsstring method should - unless can use uilabel (or similar) job you. try write least code possible , reuse code that's provided you, dropping use lower level api if requirements or performance profiling show need to.
Comments
Post a Comment