Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drawRect on top of subviews

I have subclassed UIView and added a drawRect method to it. Then I define a view using this custom class and add subviews to it.

The problem is that drawRect seem to draw stuff under the subviews (hence not visible).

I want stuff that drawRect draws appear above the subviews of my custom UIView.

Is this possible?

like image 645
RawMean Avatar asked Oct 08 '11 06:10

RawMean


1 Answers

A subview will always be drawn on "top" of its superview.

Depending on your specific requirements, you may need to have a plain UIView as the background/container view, with your existing subviews in there, and then your custom view as another subview added to the very top, so it has the highest Z-order.

This would work, for example, if your custom view was a grid overlay that should be on top of everything else. The custom view would have to be non-opaque with a clear background colour.

like image 53
jrturton Avatar answered Sep 18 '22 18:09

jrturton