Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between addSubview: and insertSubview:atIndex:?

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

like image 849
user249674 Avatar asked Jan 19 '10 02:01

user249674


2 Answers

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.

like image 144
easeout Avatar answered Nov 11 '22 00:11

easeout


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.

like image 1
Jordan Avatar answered Nov 11 '22 01:11

Jordan