Ahmed Al Abdulaal
Ahmed Al Abdulaal

Reputation: 280

Is it possible to have overlapping views with auto layout?

I'm trying to have to views overlap as shown in the picture below, but I couldn't figure out how would I go about doing it with auto layout.

enter image description here

I tried doing the bottom view programmatically, and it worked fine except for the button which I had laid out using interface builder.

enter image description here

If it's possible to have views overlap what are the constraints needed, and is there a way to let the button show on top of the view in the bottom without doing programmatically?

Upvotes: 4

Views: 2869

Answers (3)

elk_cloner
elk_cloner

Reputation: 2149

You can do something like this.

make the second view uplift with minus value:

enter image description here

Here is the output. SecondView(green) has been uplifted to -50

enter image description here

Upvotes: 1

TawaNicolas
TawaNicolas

Reputation: 646

In the interface builder, using a constraint, hook the top of the bottom view to the bottom of the top view, and then edit the constant in the Size Inspector to move it like you want.

It should look something like this: Example

Upvotes: 0

Aravind A R
Aravind A R

Reputation: 2714

You can do overlapping views using InterfaceBuilder. First create the top view i.e the one with image, give its constraints like top ,trailing,leading and bottom space. Then create the overlapping view. The constraints for the overlapping view can be its trailing space, leading space,bottom space and height. Then add those buttons inside that view.

Upvotes: 0

Related Questions