Add CALayer below UIView
20,529
Solution 1
[self.view.layer insertSublayer:CALayer below:subview.layer]
Solution 2
In Swift:
self.view.layer.insertSublayer(self.avPlayerLayer, below: self.button1.layer)
Solution 3
A more general solution where you don't have access to the subviews:
layer.insertSublayer(sublayer, at: 0)
Author by
DCMaxxx
Objective C lover. Interested in almost everything about computer sciences. Student at Epitech, currently studying abroad at RMIT, Australia
Updated on February 22, 2020Comments
-
DCMaxxx about 4 years
I got a
UIView
(let's call it superview) which contains anotherUIView
(lets call it subview).I'd like to add a
CALayer
so that it is visible on top of my superview, but under my subview. In other words, my subview's background should override the layer.I've had a look at
addLayer:below:
and others, but I'm not sure how to use it. Thanks.EDIT: My bad, I had another view between superview and subview, and I was messing with it. Thanks guys !
-
DCMaxxx over 10 yearsMy bad, I had another view between superview and subview, and I was messing with it. This works like a charm. Thanks !
-
Eugene P over 10 yearsThe answer is not correct enough. You do not need to insert you CALayer. Because if you add sublayer to your super view, this layer will definitely be under any subview of this superview.
-
Dima Deplov almost 9 yearswhat if we haven't
self.button1.layer
inself.view.layer.subalayers
? If you know the answer please let me know -
King-Wizard almost 9 yearsLet me know @flinth if my comment above helped you to fix your problem and do not forget to put a +1 for this answer.
-
Dima Deplov almost 9 yearsunfortunately not. I know these methods. Look at my question please. stackoverflow.com/questions/30564635/…
-
King-Wizard almost 9 years@flinth I just answered your question.