Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto Layout "Add New Constraints" not interactive in Interface Builder

I am updating an application for iOS 7 and have decided to use Auto Layout.

When I try to add constraints to any of the elements in the below screenshot :

enter image description here

i.e. View Controller, Table View, View, Table View Section, Table View Cell, Content View, Label.

I am unable do to so, as no item in the Add New Constraints panel ( as seen below ) is interactive. (Apart from the Update Frames Item)

enter image description here

In my attempts to resolve this issue I have researched that

"When using Auto Layout you may no longer set the frame of a view directly. This line either has no effect, or it may directly interfere with what Auto Layout is doing."

also

"When setting the contentSize of a scrollview with Auto Layout, the content size is automatically derived from the constraints that you set on its child views."

The problem is still there when I update the ViewContoller code to accommodate this advice.

like image 723
Ríomhaire Avatar asked Sep 23 '13 15:09

Ríomhaire


People also ask

What are two properties that auto layout constraints control on a Uiview?

Auto Layout defines margins for each view. These margins describe the preferred spacing between the edge of the view and its subviews. You can access the view's margins using either the layoutMargins or layoutMarginsGuide property. The layoutMargins property lets you get and set the margins as a UIEdgeInsets structure.

What are auto layout constraints?

Auto Layout constraints allow us to create views that dynamically adjust to different size classes and positions. The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.


2 Answers

I had a similar issue. I was able to add constraints for items on a Table View Cell - Content View (e.g. UILabel, UIImageView), once I switched the Table View Cell Style to Custom.

enter image description here

If I added images or UILabels on top of a default Table View Cell type (e.g. Subtitle), I could position them on the Content View, but couldn't set constraints on them.

Changing to Custom Table View Cell Style was the solution for me.

like image 105
DenVog Avatar answered Sep 25 '22 23:09

DenVog


To set the constraints you need to select the items and then set the constraints with either the constraints menu or with ctrl+drag.

However, there is no way to set constraints for a tableViewController as it is a already completely set up.

like image 23
Christian Seiler Avatar answered Sep 22 '22 23:09

Christian Seiler