Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the index of sub UIView in the parent view?

Tags:

ios

uiview

I want to use exchangeSubviewAtIndex: withSubviewAtIndex: method.

but how can i get the indexes of those views? i already have their pointers, so I thought there might be a method like.

[parentView indexOfSubview:subview];

but I couldn't find that kind of thing in Xcode documents library.

please help me! thank you in advance.

like image 691
user1922950 Avatar asked Jul 20 '13 05:07

user1922950


People also ask

How do I get Subviews in UIView Swift?

If you need a quick way to get hold of a view inside a complicated view hierarchy, you're looking for viewWithTag() – give it the tag to find and a view to search from, and this method will search all subviews, and all sub-subviews, and so on, until it finds a view with the matching tag number.

What is UIView in Swift?

The UIView class is a concrete class that you can instantiate and use to display a fixed background color. You can also subclass it to draw more sophisticated content.


1 Answers

This is how you get it:

[parentView.subviews indexOfObject:subview];

In Swift:

parentView.subviews.firstIndex(of: subview)
like image 183
Andrey Chernukha Avatar answered Oct 02 '22 10:10

Andrey Chernukha