Constraint does not work in the cell of my table view - ios

When I add some simple constraint for the cell of my table view, all of labels goes to top left of the cell.
Image of cell when it is In story board
but when I run the application all labels and everything goes to left!!!
Image of application when it is running

Try using this button and declare the constraints to a horizontal and vertical positions instead of the pin methods and declare your height and width constraints with it.

To position the labels as you want, you can specify top and left constraints using the "Add new constraints" button in the storyboard:
You should also specify height and width constraints for the labels:

Related

Set the position of a label within a cell in tableview

I have created a tableview with dynamic cells. I have added a label in a cell.
The label is always placed in centre of the cell.
I don't want it to be dynamically placed when I adjust the height of the row.
I would like to place the label 20px under the top of the cell.
How can I do this?
You can set constraints like top,leading,trailing and fixed height to that label if you are using autolayout.
Put your label in cell with 20 pixel of distance from top and then set constraints or pin constraints as mentioned above.
Hope this will help :)
Use Auto Layouts in your StoryBoard. Like these
You have to setup all the constraints in the storyboard to make it work properly.
If you use autolayout, set constraint.
Select label and Drag to upper of label by pushing control.
When popup appears, push option key.
Click "Top Space to Container"
enter image description here
Select label and look into size inspector. Modify constant value of "Top Space To" constraint to 20.
enter image description here
If using Auto Layouts, give these 4 constraints, it will work.
Drop the label on custom cell where exactly you want, give top space, tailing and leading and also a fixed height.

Set constraint for textview to the right of cell

I have got a UITableView with dynamic cells.
In each cell will be a small textview on the right side of the cell.
How can i set an constraint, which fixed this textview with a fix value of space to the right side of the cell in iOS8 Swift?
At the moment I only know, how I can set the space from textview to the left side of the cell, but I need to fix the space between textview and right side.
You can create a custom TableViewCell or in your prototype add the textview and manipulate the constraints of XIB file in storyboard. What you can do is set for example the constraints of width and height and also set the Spacing to the right side and the top side.
Or, another thing you can do is: choose the textView and then press ctrl+LeftMouseClick and drug to the left into the cellView.Like this:
When you let the click choose "Center Vertically in Container" like this:
To "Center Horizontally in Container" do the same thing as above, but this time drug to the top, int o the container cellView again.

How to Align Two UI Button Horizontally Aligned in A Xib Using Size Class and Auto Layout

How to Align Two UI Button Horizontally Aligned in A Xib Using Size Class and Auto Layout. Two Button should keep its original height and width
i would like to achieve this without code
Thanks in advance
First add gallery button:
Height constaint
Width constraint
Leading space with superview
Top space with superview
Then add camera button:
Horizontal space with Gallery button
Equal width with Gallery button
Equal height with Gallery button
CenterY with Gallery button
And it should be done.
Check this video, to set the constraints
You can check in the preview,
Select both Buttons.
Add the following constraints show in image
This will add default height depend on Text Font.
So if you want to increase height then Select any one button and add extra height constraint. Update the frame.
Just simple select Two Button and Give horizontal and vertical spacing constraints and give Equal Width and Equal Height to Button.
Connect your Gallery button to your main view's corner and set it using
Next, connect your Camera button to Gallery button and set Horizontal Spacing.
Inside your Storyboard's Leading Alignment Contstraint, set Gallery.Trailing as First Item, and Camera.Leading as Second Item. Set Relation to Equal.

Autolayout TableView Issue

I'm having a strange issue with my tableview, debugging the view hierarchy i'm getting this
I've tried a lot of constraints with no result, how should I setup my tableview to avoid that kind of misplacement ?
Edit
I've a custom cell with an image view, actually set just this 5 constraints
Top, bottom, leading and trailing values are 0
You just need to set Your UITableView constraint to Leading,Trailing, Top and Bottom. and also for your UIImageView set same constraint. so your imageview will show fit to cell as per table width. no need to set Align Center X constraint.

Adding UIButton to custom cell with auto layout

I am trying to add a button through IB in a custom cell at top right corner of the cell. I am using auto layout to position it correctly but in simulator I don't know why the button wont show up.
But if i create it programmatically then it shows up perfectly.
So my question is how can achieve it using IB and where i am doing it wrong.
I have added four constraints on my button leading and trailing space to superview and fix width and height.
Remove leading space constrain and add fix to top space constrain. I mean there will be total 4 constrains Fixed width, height and fixed trailing, top space to super view and it will work. If it is not working means you have not set your tableView constrains. For tableView fix it from top,bottom,left and right space from super view.

Resources