UITextView drawing

Discussion in 'iOS Programming' started by MrFusion, May 9, 2014.

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    The drawRect in UITextView does nothing. All the drawing is done by the NSLayoutManager. Every time you type something, the text system notifies the NSLayoutManager and the text is redrawn. But how does the layout manager knows when to draw the initial text or how does it detect that the view has loaded?

    setNeedsDisplay doesn't do anything either.
     
  2. pmau macrumors 65816

    Joined:
    Nov 9, 2010
    #2
    UITextViews are automatically embedded in UIScrollViews.
    If you look at the class documentation you see that UITextView has a textStorage, which is a subclass auf NSAttributedString.

    If you modify the attributedString, the layoutmanager will notice triggers a relayout and will advice the UIScrollView to redraw the changed regions.

    The view itself knows when it's part of a visible view hierarchy after being added as a subview.
     

Share This Page