Reputation: 588
If i have code like:
self.view.addSubview(SomeImage1)
self.view.addSubview(SomeImage2)
self.view.addSubview(SomeImage3)
How do I switch places of view, i understand that the first one would be at index 0 and second at index 1, so is there a way to manually set view index, i am new at managing view and havent found any tutorial good enough to solve my problems.
Upvotes: 1
Views: 206
Reputation: 22866
There's a full set of UIView methods that copes with that:
func bringSubviewToFront(_ view: UIView)
func sendSubviewToBack(_ view: UIView)
func removeFromSuperview()
func insertSubview(_ view: UIView, atIndex index: Int)
func insertSubview(_ view: UIView, aboveSubview siblingSubview: UIView)
func insertSubview(_ view: UIView, belowSubview siblingSubview: UIView)
func exchangeSubviewAtIndex(_ index1: Int, withSubviewAtIndex index2: Int)
...and so on.
You shouldn't be using array indexes to move views.
Upvotes: 3