Difference between addSubview: and insertSubview: atIndex :?

When adding subviews to a UIView , what's the difference between the addView: and insertView:atIndex: ?

+4
source share
2 answers

Both add a view to the receiver as a sub-view, which forces 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 list, which puts it on top of other subzones when drawing.
  • insertSubview:atIndex: adds your presentation to a specific position in the list, which places it above the supervision that appears in front of it in the list, and under the subzone that appears later.

[parentView addSubview:childView] same as [parentView insertSubview:childView atIndex:[[parentView subviews] count]] .

All you need to know is here .

+15
source

AddView adds a view to an array of views.

Insert View adds the view to a specific position in the array.

In addition, check the documentation.

+1
source

All Articles