When adding subviews to a UIView
, what's the difference between the methods addView:
and insertView:atIndex:
?
Both add a view to the receiver as a subview, which causes the view to be displayed if the receiver is displayed and positioned relative to the receiver.
But,
addSubview:
adds your view to the end of the subview list, which places it on top of the other subviews when drawing.insertSubview:atIndex:
adds your view at a particular position in the list, which places it above the subviews that come before it in the list, and below the subviews that come afterward.[parentView addSubview:childView]
is the same as [parentView insertSubview:childView atIndex:[[parentView subviews] count]]
.
Everything you need to know is here.
AddView adds a view to an array of views.
InsertView adds a view into a specific position in an array.
Other than that, check the Documentation.
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