Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to programmatically reorder items within a UIStackView in IOS?

How can one programmatically reorder items within a UIStackView in IOS?

(i.e. I can not see a function at https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIStackView_Class_Reference/#//apple_ref/doc/uid/TP40015256-CH1-SW30 to cover this)???

like image 927
Greg Avatar asked Jun 09 '16 05:06

Greg


People also ask

How to reorder the Order of subviews in a uistackview?

Or you can do the reordering in the code via using UIStackView ‘s arrangedSubviews property. This array gives you the current subviews in the stack view and by using insertArrangedSubview and removeArrangedSubview every items’ order can be manipulated.

What is the uistackview in Android?

The UIStackView is a nonrendering subclass of UIView; that is, it does not provide any user interface of its own. Instead, it just manages the position and size of its arranged views. As a result, some properties (like backgroundColor) have no effect on the stack view.

How do I use a stack view in Jira?

To use a stack view, open the Storyboard you wish to edit. Drag either a Horizontal Stack View or a Vertical Stack View out from the Object library, and position the stack view where desired. Next, drag out the stack’s content, dropping the view or control into the stack. You can continue to add views and controls to your stack, as needed.

What happens when a subview is added to a stack view?

When the stack view adds a view to its arrangedSubviews array, it also adds that view as a subview, if it isn’t already. When a subview is removed from the stack view, the stack view also removes it from the arrangedSubviews array.


2 Answers

When adding a view to a parent view, it is automatically removed from it's old parent view.

This is the same with arrangedView, so you only need to use insertArrangedSubview(_:atIndex:) and addArrangedSubview().

Using removeArrangedSubview() is not needed.

like image 107
Aviel Gross Avatar answered Oct 21 '22 14:10

Aviel Gross


surely you can use a combination of

removeArrangedSubview(_:)
insertArrangedSubview(_:atIndex:)

to reorder your views?

like image 26
Fonix Avatar answered Oct 21 '22 13:10

Fonix