Search code examples
iphoneobjective-cuiviewsubviewdrawrect

iPhone - UIView adding a subView vs drawRect?


What are the differences between adding a view as a subView VS drawing the view in that view's drawRect method?.

I use both approaches, but I was wondering apart from the obvious such as, if you do in drawRect it will be a single View, as opposed as two views, or adding as a subview is just easier. Are there any specific situations where you should definitely use one over the other?


Solution

  • Overriding -drawRect: can be a good way to draw complex UITableViewCells. Having all of the subviews composited and drawn as one view helps table view scrolling performance immeasurably.

    Having said that, I typically stick with the highest level API available and drop down to a lower level only if performance suffers.