I have a custom view which is a subclass of UIView
. I added some sublayers to the custom view but now I want remove them.
I tried doing this:
self.layer.sublayers = nil;
But this will remove everything including the initial sublayers of the view.
Is there any way to achieve this? Or do I have to reinitialise a new custom view every time?
Note: App runs in iOS 7 and above.
Thanks!
Keep a reference to the sublayer added Remove the sublayer from the super layer when not needed.
The code would be like:
Obj C:
[thesublayer removeFromSuperlayer]
Swift:
thesublayer.removeFromSuperlayer() //thesublayer is the name of the layer you want to remove
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With