Derek
Derek

Reputation: 3016

Layout challenge in xcode

Here is an image of what I want my page to do, this displays initially disabled View

and when Tips are selected, everything moves down accordingly, enabled View

This was created in android studio and it was simple, just have a layout that is "gone" and display when needed, everything would adjust itself.

However I am having a hard time trying to do that same in Xcode.

What I have tried to do was create a container view and link constraints so that when the size of the container view changes the label and switch would also move.

But when I add vertical spacing and then move the container it just increases the vertical spacing so it stays in the same position.

Upvotes: 0

Views: 50

Answers (1)

MSU_Bulldog
MSU_Bulldog

Reputation: 3519

Add all of the Tip Type objects inside a UIView. Then add a height constraint on the UIView. You can set that height constraint to 0 when you want it to be hidden and 100 (or whatever height you need) when you want it to be shown.

Declare the NSLayoutConstraint:

@property (nonatomic, strong) IBOutlet NSLayoutConstraint *heightConstraint;

In storyboard, make your connection to the height constraint of your UIView.

Use the following code to hide the UIView:

heightConstraint.constant = 0;

Then to set the height to 100 (or whatever you want):

heightConstraint.constant = 100;

Upvotes: 1

Related Questions