I am trying to add UITextFields to the contentViews of some static UITableViewCells. If I just add them directly to the cells in the storyboard, I get several of the following warning in Xcode 5:
Ambiguous Layout: Position is ambiguous for "Round Style Text Field".
If I then select the UITextFields and choose "Add Missing Constraints" in the storyboard, I then get this warning instead:
Misplaced View: Frame for "Round Style Text Field" will be different at run time.
In addition, I've tried adding constraints between the UITextField and the the contentView manually (by selecting those two views and trying to add a constraint), but it seems like none of the constraint options are available for that particular relationship (checkboxes are all disabled)
Here are some screenshots of the Storyboard:
In the view controller panel to the left of storyboard there will be a yellow circle with an arrow Arrow, click it.
Then in the new panel click the yellow triangle with a circle in the middle.
You should get three options:
Update Frame - this will move the UI element to match the orange dotted box
Update Constraint - this will update the constraints to match the current UI element
Reset to suggested constraints - Xcode will do what it thinks is right
In your case update constraints should work
I was having similar issues - unable to add ("Pin") constraints to the embedded UITextField, getting warnings about it, etc. The OP didn't specify, but from the screenshot it appears the static UITableViewCell's Style is set to one of the pre-defined types ("Left Detail", in particular).
I found that setting the Table View Cell "Style" dropdown to "Custom" will magically enable adding constraints to the UITextField, at the cost of having to re-build the pre-defined cell style yourself - e.g. adding the UILabel(s) and matching their alignment to the other cells.
Related
I added a Storyboard launch file to upgrade a project from iOS 4 to iOS 9. The app runs in the Simulator but nothing I do will centre views for iPhone5 and iPhone 6 or scale them to fill the frame. Instead they look like bonsai versions of an iPhone 4 pinned in the top left of the screen.
When I try to add constraints to centre the views by following the procedure described here, the menu will not give me options to choose the view I need to constrain.
Instead I get this.
The bottom two - Horizontally in Container and Vertically in Container - are the only options I can check. But pulling down on the arrow to the right of the text box only gives some of the options needed to Add Constraints
What do I need to do to enable the view option ?
EDIT 1.
And furthermore, when I try to constrain width and height I get this
All six options are in grey and none of the text boxes change
EDIT 2.
And using the Size Inspector to look at the view I am trying to centre and fill, the view has no constraints as shown below.
It is really starting to look like there is no simple way to launch an old app where views have been created programmatically and have Storyboard Launch automatically layout views to suit different iPhone screen sizes.
The "Horizontally in Container" and "Vertically in Container" checkboxes affect individual views. The are "binary operations". If you select more than one view, these checkboxes cause all the views to be centered in their container.
In contrast, the other checkboxes in this popup align groups of views.
If, for example, you select 4 views and click "leading edges" then it creates a set of constraints that line up the leading edges of all the selected views. (Under the covers it creates enough pairs of constraints to line up all the views by their leading edges.)
If you only have 1 view selected then only the bottom 2 checkboxes ("Horizontally in Container" and "Vertically in Container") are meaningful and the others are dimmed. As soon as you select more than one view the others should be enabled.
I had the same problem because on Show the Size inspector > Layout, "Autoresizing Mask" was selected, by changing the value for "inferred (Constrains)" it will resolve this problem
illustration
Select the view you would like to constrain. Then tap the button to the right of the one you have selected and use that menu to define your autolayout constraints. If you want it to work for all devices make sure your storyboard is on the wAny hAny size class setting.
I am having pretty crazy amounts of issues trying to align two labels inside a table cell:
The problem is I need both labels (the region is clickable) to be centred within their cell. I can only seem to get the layout centred based one or the other.
Is this too much to expect from autolayout?
Embed the labels in a new view, then centre that view with autolayout. Also, let this new view resize itself according to the labels
So:
- Add leading and trailing constraints between labels and their superview (new view)
- Centre the new view in the UITableViewCell
I just got home, so I opened up a fresh project, with good news :)
So I set up what I described earlier, 2 labels inside an UIView
Select the labels and go to the Size Inspector, there check 'Explicit' and in the 'Preferred Width' add the Maximum - make it the maximum it is allowed to be
Now in code, you can set the labels and they auto-resize!
This is a button created with interface builder:
What is this orange dashed line (button text area, right?), why this is outside the button and how do I make it be inside the button (if this is the case)???
It's because you have auto layout on and that's what it thinks the size and position should be based on the constraints. Sometimes it shows this when the element is moved or resized without adjusting constraints, other times it shows because the constraints given are ambiguous.
Google auto layout. You haven't provided all the required constraints or they aren't the ones you want. The red box indicates where your button would be if it follows the provided constraints.
One possible fix: in interface builder, you see a few buttons on the bottom right. click the third one and then select update constraints.
I have MainStoryboard.storyboard file for all my views creation. In that, one of my view controller scene contains UITableView with 3 different UITableViewCells in it. Out of three, two are default UITableViewCell whereas one is CustomCell. Please find the same below:
(Image 1 :For a default cell where text is displayed using cell.textLabel.text)
(Image 2 :For a custom cell where there is a custom cell class is implemented and UI is based upon storyboard design.)
But, while changing this tableview to edit mode, selecting minus sign for this cell, the cell does move to left side, hence the text in it, looks like it got cropped from left side. This happens only for iOS7 not in iOS6.
Please let me know what could be the solution for this.
Need to set AutoLayout Constraints to label in custom cell,
To right side label in custom cell add Leading space to superview auto layout constraint.
Select Label in StoryBoard -> Editor -> pin -> Leading Space to SuperView.
I am trying to learn to use layout constraints in interface builder but I am running across an issue...
I've got two views, one UILabel and one UIImageView, and I'd like a layout as follows:
the label should be centered in the superview
the imageview should be a set distance to the left of the label
Seems pretty simple, but I can't figure out how to impose a constraint for the second condition (the first is done automatically). Anyone know how to do this?
Thanks!
Click on both views while holding the command key so they're both highlighted. Then click on the pin button in the bottom right hand corner of IB (the middle button). Select horizontal spacing and the constraint should now be added. You should be able to adjust it as needed from there.