Cory Imdieke
Cory Imdieke

Reputation: 14828

Combining drawRect with other UIViews

I normally do all of my "drawing" using a composition of other UIKit components, adding them and positioning them as necessary in my view. Pretty standard stuff - image there, label here, nothing too spectacular. I don't use drawRect much, which is why I'm still a little slow on its exact usage.

I'm now tasked with making a fairly complex view (UIView subclass), which will have quite a few different things going on (animations, images, labels, etc) but will also need some custom drawn aspects (color-filled rectangles, nothing too complex in terms of drawing) which would be done in the drawRect function.

My question is this: If I draw those custom aspects in my drawRect function, overriding UIView's default drawRect (does it actually do anything?), will my other subviews still get drawn in my view? What order will they get drawn on? Will the subviews go on top or below my custom drawing code?

I could probably just code some things up and see what happens, but I'd like a bit more detail in-depth of what's actually happening.

Thanks!

Upvotes: 3

Views: 565

Answers (1)

David Neiss
David Neiss

Reputation: 8237

Subviews will get drawn on top of your drawRect stuff, just as if you didnt drawRect and you had subviews.

BTW, try "Opacity" program if you want something to write the drawRect code for you (it will export CG code you can paste into drawRect).

Upvotes: 3

Related Questions