![]() I’ve created a very simple example project that presents a series of buttons vertically and horizontally. You don’t need to call addSubview as this will be handled for you automatically. To add a new view you just need to add it to the stack view’s array of arrangedSubviews by calling the addArrangedSubview method of UIStackView. UIView *myView = stackView.arrangedViews The example below shows how to remove a view simply by setting it’s hidden value: The stack view will automatically remove the view from the view hierarchy redistribute and position it’s other views shifting them up and resizing them if necessary. In contrast, to remove a view in a stack view all you need to do is find the view you want from the stack view’s arrangedSubviews property, set the view’s hidden property to false and that’s it. This can lead to a lot of messy and convoluted code. Prior to iOS 9 you would have to layout all the views yourself, create lots of constraints, keep strong pointers to some of the constraints and enable/disable these constraints while managing the view hierarchy. ![]() The real power of stack views becomes obvious when you want to add and remove views from a stack at run-time. Of course you could also use stack views to build entire interfaces and even grid layouts. Stack views could be used to present a small list of images or buttons to the user without having to mess around with UITableViews and where you don’t need cell reuse or a datasource. No constraints, outlets of code was harmed in the making of that layout! When to use Stack View?Īpple thinks that stack views are so useful that they have added a dedicated button on the Interface Builder canvas to wrap the selected views in a stack view. The last row contains a horizontal stack view containing three more buttons. The above image shows how you can use a stack view to display buttons vertically. Stack views leverage the power of Auto Layout to size and position their views without you having to worry about defining the constraints yourself. You can also nest stack views within other stack views and create complex layouts. You can adjust the stack view to distribute the views in different ways, set spacing between the views and add/remove views at runtime while animating the changes. UIStackView takes a collection of views and lays them out in either columns or rows. If you’ve ever developed apps for Android then you’ll be familiar with Linear Layout, essentially UIStackView is Apple’s equivalent. This is a brand new control that is being added to UIKit in iOS 9. In this article we’ll cover the following four new technologies and APIs that were introduced at WWDC: I’ve now had some time to watch some specific WWDC sessions.Īlso, I've had a play with some of the new and exciting APIs that will be available on iOS 9 and some of the new features of Xcode 7. This is good for localization - stretching UILabels, etc.What are the key implications for developers that came out of WWDC 2015? Four new technologies and APIs introduced at WWDCĪfter watching the 2015 WWDC Keynote I was excited by some of the APIs that Apple have announced.Set priorities a little higher or lower than the defaults: Use proportions - will likely be more successful.intrinsicContentSize = automatically makes the size constraint the same size as the content within the view.Keep references to constraints you need, don’t just blindly deactivate all of them.Instead, activate and deactivate constraints.Start with Stack View, use constraints as needed.New options: Content hugging priority, content compression resistance priorityĬan resist changing sizes (useful for things like tab menus, buttons, etc.). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |