Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add constraints on a fresh custom view in Xcode 11.x (.xib file)

Tags:

xcode

ios

xcode11

Designing custom views with Xcode 11.2 (11B52) or 11.2.1 (11B500), I met some situations where I cannot create constraints onto the view and its subviews.

It may be hard to reproduce since it is embedded in an existing project, but in this particular, just creating an empty view via :

File → New → File... → User Interfaces → View

If I add some components from the object library, then I cannot add constraints via Ctrl-click or the bottom right icon

Cannot add constraints

In my previous attempt, I correctly bound it to my swift class, even if there was no controller yet.

I suspect I wrongly configured something related the "Auto Layout" feature, but have no clue where it is now. If I copy/paste a tree view from a existing storyboard where the constraints are properly editable, then it is possible to add constraints without issue.

enter image description here

The side-by-side comparison does not show any obvious difference in the various inspectors.

What is the right approach to avoid these constraint locking issues ?

like image 640
user1556814 Avatar asked Dec 10 '22 01:12

user1556814


1 Answers

There is probably a configuration issue somewhere in this existing project,

But in the meantime, to anyone falling in this use case, a possible workaround is to set Automatic in the Layout section of the Size inspector. By default, in my existing project, it is set to Translates Mask Into Constraints each time I create a new view and add object via the Object Library.

enter image description here

like image 81
user1556814 Avatar answered Dec 28 '22 08:12

user1556814