Is there a method called viewDidLayoutSubviews?
I need to add CALayer to UILabel but only after UILabel has changed its frame. The UILabel changes its frame in the method viewDidLayoutSubviews
, and if I add a CALayer, it creates multiple instances of CALayers as it gets viewDidLayoutSubviews
called multiple times. I tried to remove all CALayers before adding a new one, but sometimes that also removes the text. I just used self.eventAttending!.layer.sublayers = nil
to set subwords to null.
So I think the simplest answer to my problem is to simply add the CALayer after the frame has been set to viewDidLayoutSubviews
, which brings me to my question: which method is called after viewDidLayoutSubviews
?
source to share
There is no method that is always called after viewDidLayoutSubviews
, that is called during the creation process, but it can also be called when things happen to your view, such as adding a new subview.
Your best bet is to create a reference variable on your layer so you can remove it, adjust it as needed, or just check if that reference variance is not null and then don't recreate it.
source to share