Adding constraint to the “main view” in a xib

百般思念 提交于 2019-12-05 06:17:41

This actually is possible.

Simply put the view you'd like to constrain into another view, like the highlighted view here.

Then, add your desired constraints.

Finally, pull the view you just added constraints to out of its parent view. You can now add constraints to that view.

Para

As you've surely found out by now, it looks like there's currently no way to set Autolayout constraints at the main UIView level from Interface Builder.

I had a similar problem here (Launch Screen XIB: Missing Width / Height Constraints (Xcode 6)), while working with the launch screen of my app.

The only workarounds I found, if you want to keep working with IB, are:

  • Using a UIViewController and its UIView inside the XIB, instead of just a UIView
  • Working only with Storyboards (and, once again, UIViewController)

However, I understand these approaches may not be ideal or "clean", especially if you simply have a subclass of UIView and you want to draw its interface in a good old XIB.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!