Patrick bateman
Patrick bateman

Reputation: 63

Swift stack view in storyBoard

Im having an issue with my layout in my story board. When i make a stack view how can i adjust the size of the UIlabel box to fit more text? Image Example:enter image description here

Also how can i get rid of the stack view to bring everything back to its original state?

enter image description here

Upvotes: 0

Views: 955

Answers (2)

Wang90925
Wang90925

Reputation: 142

I have given you a brief overview of auto layout. The examples that we have worked on were pretty easy. However, as your app UI becomes more complex, you will find it more difficult to define the layout constraints for all UI objects. Starting from iOS 9, Apple introduced a powerful feature called Stack Views that would make our developers' life a little bit simpler. You no longer need to define auto layout constraints for every UI objects. Stack views will take care of most of that.

In this chapter, we will continue to focus on discussing UI design with Interface Builder. I will teach you how to build a more comprehensive UI, which you may come across in a real-world application. You will learn how to:

Use stack views to lay out user interfaces. Use image views to display images. Manage images using the built-in asset catalog. Adapt stack views using Size Classes. On top of the above, we will explore more about auto layout. You'll be amazed how much you can get done without writing a line of code.

What is a Stack View

First things first, what is a stack view? The stack view provides a streamlined interface for laying out a collection of views in either a column or a row. In Keynote or Microsoft Powerpoint, you can group multiple objects together so that they can be moved or resized as a single object. Stack views offer a very similar feature. You can embed multiple UI objects into one by using stack views. In most cases, for views embedded in a stack view, you no longer need to define auto layout constraints.

Quick note: For views embedded in a stack view, they are usually known as arranged views. The stack view manages the layout of its subviews and automatically applies layout constrants for you. That means, the subviews are ready to adapt to different screen sizes. Furthermore, you can embed a stack view in another stack view to build more complex user interfaces. Sounds cool, right?

Don’t get me wrong. It doesn’t mean you do not need to deal with auto layout. You still need to define the layout constrants for the stack views. It just saves you time from creating constraints for every UI element and makes it super easy to add/remove views from the layout.

Upvotes: 1

Shades
Shades

Reputation: 5616

To add more text- simply type more text. The label adjusts itself.

To get rid of the stack view- select the stack view and go to Editor->Unembed

Upvotes: 2

Related Questions