Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect when my UIView subclass is added to another UIView

Tags:

ios

uiview

I want my UIView subclass to position itself automatically when it is added to a parent container view.

Can I somehow detect when it is added and run my positioning code then or do I need to do something like?

[parentView addSubview:subView];
[setView calcPosition];
like image 883
trapper Avatar asked Feb 19 '23 19:02

trapper


1 Answers

UIView provides the methods willMoveToSuperview: and didMoveToSuperview. Just override those to know when the view is added to another view (or later removed).

like image 75
rmaddy Avatar answered May 07 '23 21:05

rmaddy