ios - UITextView drawing text twice -


i'm trying create stroked text on uitextviews text. it's working fine, text drawing twice on screen. here drawrect method in subclass of uitextview...

- (void)drawrect:(cgrect)rect {     // drawing code     // drawing code      uifont *font = [uifont fontwithname:@"cochin" size:[_fontsize floatvalue]];      cgcontextref context = uigraphicsgetcurrentcontext();     cgcontextsetshadow(context, cgsizemake(1, 1), 1);     cgcontextsetrgbfillcolor(context,1,1,1, 1);     cgcontextsetrgbstrokecolor(context, 0, 0, 0, 1);     cgcontextsetlinewidth(context, .35);     cgcontextsettextdrawingmode(context, kcgtextfillstroke);     cgcontextsavegstate(context);     [[self text] drawinrect:rect withfont:font]; } 

i tried setting clearscontextondraw yes, didn't trick. please...

i've tried code , work me. there couple of notes though:

  1. you should use self.bounds target rect draw to, not rect parameter get, since means 'this invalid area of view'. performance optimization , need use it.

  2. you don't need call cgcontextsavegstate (and when do, want restore after that). when call subroutine modifies current context (and restore afterwards), ideally, should moved routine itself.

try setting background of view white , make font bigger, might hints of what's going on. also, post screenshot here.

update:

i haven't noticed using uitextview. should not use class , custom drawing! if wanna draw text yourself, subclass uiview. if wanna use uitextview, use attributedstring property of uitextview (set in viewdidload example, in uiviewcontroller subclass. here's more info on attributed strings: apple docs


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -