drawRect over subviews?

前端 未结 3 564
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 17:42

I created a container view that holds a bunch of child views - a collection view, a custom toolbar and some bits and pieces.

The design has a border on the top, lef

3条回答
  •  温柔的废话
    2021-01-12 18:39

    Drawing happens beneath all subviews of a UIView. Think of it as being on the very base - an actual part of your view - and then each subview is added on top of your view. To make the drawing above the subviews is the same as wanting for the subviews to appear under the view, while still being subviews. Perhaps that analogy makes it clearer why it must always be on the bottom. And it also leads you logically to the solution:

    To get the drawing to appear above subviews, simply create a new UIView subclass to place the drawing code inside, and place this above all other subviews.

    It might also be a good idea to override your UIView's addSubview: implementation, to ensure your subview always remains on top.

提交回复
热议问题