I'm having problem with using constraints inside a UITableViewCell. I want to place a UIView inside a UITableViewCell just to use the UIView as a frame, so the UITableViewCell looks like a Cell with borders.
The problem is as soon I drop the UIView inside the Cell and click "Add missing constraints", I get a warning: "Layout attributes relative to the layout margin on iOS versions prior to 8.0".
I looked for a solution but all the solutions here did not work. When I try to uncheck "Relative to margin" option, like in the top answer to the linked question,the warnings are gone but the UIView covers the full cell. But I want small borders around the UIView.
Here are some photos how it's looking right now:
Before I uncheck the "Relative to margin" option in my constraints (Thats how it should look like!) :
And after I unchecked them:
Can someone help me out? Thanks
EDIT
Thanks to Kris Gellci. I found the solution. After I unchecked the margins box, I had to reset the vertical and horizontal Space constraints. Now it works fine.
Click on each constraint and make sure that none of them are have the "relative to margin" set on either "First Item" or "Second Item". Unselecting the relative to margin will then require you to reset the constant on the constraint. Attached are some screen shots for reference:
Related
I want to show margin space left and right in UITableView look like images. I used Xcode 7.3.1 and deployment target is 7.0. Please help me! Thanks very much.
You have to add one UIView into cell's contentview and than give constraints to it like below ...
Note: Don't forget to add background color to cell's contentview to see the effect.
Add left and right constraints as shown in pic below. You can change the margin to the value that you need. Dark red (vs dotted red) connectors says the constraints are selected. Click on "Add 2 constraints" to add it.
I am trying to use the constraints on xcode 6 with side-by-side objects but when I use the "add missing constraints" option, all of the elements resize properly except the side-by-side buttons where they stay the same size but one gets pushed out of the view.
Image of View
And I think I need to use the "Equal heights" constraint but it is greyed out :(
Greyed out constraint Image
Can anyone help?
You need to right-click drag from one of the objects to the other one to enable that option (It needs to know what heights should be equal)
You can also:
In the Xcode document outline use Shift or Command and click on the items you want to add the equal size constraint to.
Then click the Pin button.
You can now click the checkbox to add 'equal width' or 'equal height' constraints.
I am using storyboard in an iOS/xcode project with the following simplified "hierarchy" (from top to bottom):
ViewController (not a TableViewController for some customizing reasons)
View
TableView (and some other content that does not matter I think)
Cell
ContentView
"AnyView" (specific type seems to be irrelevant, as the following happens for every item I tried)
When I set the constraints between AnyView and ContentView to Zero Spacing for Top/Bottom/Leading/Trailing there is still quite some "space" between the ContentView and AnyView. (I have never encountered this when doing similar things just programmatically.)
In order to get rid of that spacing I looked for everything in storyboard options that sounded even remotely like spacing / intending etc., but did not really succeed.
By accident I just realized that when I drag & drop a view into the ContentView in a certain way it appears that storyboard sets a negative spacing of -8 that seems to "remove" that spacing. I could just use that number in my constraints, but it seems somewhat random. Does anyone know what the reason for my unwanted spacing might be or if that -8 has a deeper meaning (e.g. maybe Apple is forcing some design guidelines onto storyboard users that way?)?
Thank you very much for any insights!
In Xcode 6 constraints can be "relative to margin". The margin is set as the normal default spacing to the edge of the screen.
You can turn this off in the "add constraints" button...
Or in the constraint property inspector...
I know this may sound weird, but the only solution for me to remove top padding in UITableViewCell is to remove the existing "Top Space" constraint and add it back and setting it to 0.
I have read a lot of SO question about this already but nothing seems to work in my case. Simply when you add a UITableView and you test it and rotate the screen it will keep the width of the portrait orientation.
How can I make it so that it will always fill the screen's width for any screen size?
EDIT : My size inspector
Use the Autosizing feature in Storyboard for your UITableView. How to set it:
1.Select your UITableView.
2.Open the right pane -> Size Inspector:
3.Scroll down to the View section, here you'll see the Autosizing menu:
Don;t forget to disable Autolayout feature:
You're using AutoLayout in your XIB, so the AutoResizingMask stuff isn't your best route to success. You need to set the autolayout constraints on your TableView so that there is a 0 px gap between the leading (left) and trailing (right) sides of the TableView and its superview.
You can see from your screenshot that you already have some constraints in place, but they're probably not correct. I suggest you start by resetting all the existing constraints: I find that's usually best when I've got confused about where I am with constraints.
Select the top level view in your XIB file
Select Editor -> Resolve Auto Layout Issues -> Clear All Constraints in View from the menu
Select your TableView
Select Editor -> Resolve Auto Layout Issues -> Reset to Suggested Constraints from the menu
If that does the trick for you, I'd advise that you spend some time getting familiar with AutoLayout and review the constraints generated: you can select and edit them in the size inspector. This is also a pretty good tutorial.
For custom views, I often add my constraints programmatically as it's really easy to keep track of them - they're much more visible than when they're built in IB. I use a set of categories, provided by another SO user, that you'll find here and they make the code very easy to read and maintain.
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.