Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set constraints for root view in XIB?

Recently i was following a tutorial to create frameworks in Swift, Where they create reusable visual effect view just like we see in Xcode build success pop up. I was doing the UI step by step where they created a new xib file and dragged and dropped UIVisualEffectView into it.

Empty UIVisualEffectView without constraints

In the above image we can see that the UIVisualEffectView doesn't contain any constraints. It only has auto resizing masks in size inspector(as expected).


But the following image from the tutorial suddenly contains all necessary constraints for it's root view.

UIVisualEffectView with constraints

I'm already aware that we CANNOT, by default set any constraints for the root view. But in the tutorial the author seems to have added constraints for the same. I'm just curious to know if it is possible to do that or am i missing any fundamental idea ?

EDIT:

Constraints for root view.

UIAfterEffectView constraints

like image 707
Dinesh Nagarajan Avatar asked Mar 06 '23 10:03

Dinesh Nagarajan


2 Answers

OK, found one way to do this...

Haven't done any testing, so I'm not sure if the constraints are really set correctly or will be used by auto-layout at run-time, but this will put them there.

Create a new "View" XIB - this is how it looks to start:

enter image description here

Add a Visual Effect view to this view, and give it width and height constraints of 230 / 230:

enter image description here

Now, drag that Visual Effects view *out of the plain view, onto an empty space:

enter image description here

You will see it maintains its constraints. Then delete the original view, and add the other elements:

enter image description here

like image 105
DonMag Avatar answered Mar 12 '23 10:03

DonMag


As you can actually see on your screenshot the width/height constraints belong to the View (first subview of Visual Effect View).

Look at the green line:

enter image description here

like image 40
Lukas Würzburger Avatar answered Mar 12 '23 10:03

Lukas Würzburger