Calvin
Calvin

Reputation: 8765

How do I use CGContext to draw on top of an existing UIView?

I have a subclass of UIView in which I've added some subviews to in my initWithFrame method. I've added a background, amongst other things.

I want to draw some shapes on top of these views (which happen to cover the entire screen). But, when I implement drawRect: to draw these shapes, they didn't show up. Upon removing the other subviews, I realized that the shapes were begin drawn "under" the other subviews.

How can I draw them on top?

Upvotes: 0

Views: 1966

Answers (2)

Rob Napier
Rob Napier

Reputation: 299355

Call [super drawRect:rect] at the beginning of the drawRect: for the owning view. This will draw all the subviews into the current context. Additional drawing you do for the owning view should then go on top.

Upvotes: 3

kpower
kpower

Reputation: 3891

Maybe, you should add transparent view on top of others and draw shapes on it?

Upvotes: 0

Related Questions