objective c - kCGTextStroke's Fill and Stroke aren't positioned correctly -
so i'm using code below apply stroke (and fill) text in uilabel
, , it's coming out image below. stroke heavier on 1 side other (look @ top of letters compared bottom, , right compared left. period @ end makes noticeable, too, looks googly eye). i've not got shadowing turned on @ all, don't think it's shadow interfering stroke.
what causing this?
- (void) drawtextinrect: (cgrect) rect { cgcontextref c = uigraphicsgetcurrentcontext(); cgcontextsettextdrawingmode(c, kcgtextfillstroke); cgcontextsavegstate(c); cgcontextsetrgbfillcolor(c, 1.0, 0.0, 0.0, 1.0); cgcontextsetrgbstrokecolor(c, 0.0, 1.0, 0.0, 1.0); [super drawtextinrect: rect]; cgcontextrestoregstate(c); }
edit: so, kicks, took @ @ label fill, , stroke. turning off stroke creates normal-looking piece of text, if i'd coloured in interface builder. turning off fill, however, shows stroke, doesn't heavier on side other. **this leads me believe issue where fill positioned in relation stroke, , neither fill or stroke @ fault. other thoughts on this? how can fill directly centred in stroke?
you should use kcgtextfillstroke
drawing mode , draw once (with separate stroke , fill colors set).
cgcontextsetrgbfillcolor(context, 1.0, 0.0, 0.0, 1.0); // color want (this red) cgcontextsetrgbstrokecolor(context, 0.0, 1.0, 0.0, 1.0); // color want (this green) cgcontextsettextdrawingmode(context, kcgtextfillstroke); [self.text drawinrect:rect withfont:self.font];
alternatively stroke afterwards. strokes drawn center means half of width inwards , half outwards. mean if fill after stroke of stroke going covered fill.
Comments
Post a Comment