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 :
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)
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With