Set constraint for textview to the right of cell - ios

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.

Related

Sliding Text In a Label

In my Xcode Project I have a tableview that is populated with a label. Sometimes the text in the label does not fit all the way causing the label to cut off the rest of the text. So I will like to add in a sliding effect in the label where it will show the beginning text and then start to slide all the way to the end of the string and back only when the user is not scrolling in the tableview. How will I implement this?
Just assign the leading, trailing, top, bottom constrains of this label = 0 with the cell itself and let the tableView to calculate each cell's size dynamically

Constraint does not work in the cell of my table view

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:

lateral cell space tableview Swift

I have a UITableView with various cells and I want to insert lateral space (to the right and to the left) between the cell and the View, but I am not able to do that.
Can anyone help me with this?
You should use a UICollectionView instead.
With UICollectionView, you can set the Cell's Width and Height, and add custom spacing between each cells. You can also configure the space between the cell and the border of the CollectionView.
If you really need a UITableView, try to add a Leading Space To Container Margin and a Trailing Space To Container Margin contraint between your UITableView and its Superview.
Here is an example : my tableview has a grey background, my cell has a yellow background and the superview has a blue background. Thank to the two constraints, there is a space on the left and the right of my cell
Is that what you need ?
One way is to make the TableView's width shorter that the controller's view width and add constraints to keep the space exactly as you want it.
Another way is to design your cell with an "internal container" with spacings to edge of the cell's content view.
You can easily do this in a storyboard using a container view…
Add a container view to your view controller, set the left and right constraints to the inset you need, add a UITableViewController and then drag from the container to the table view controller and embed it

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.

UITableViewCell with two labels wont center

I have a UITableView below that has a custom uitableview cell. I am trying to get the two labels inside it do be 50% in width and have the left cell have right aligned text and the right cell to have left aligned. Any clue why this isnt working correctly below?
Use auto-layout, and set both the labels an equal width constraint, it should do the trick.
Edit:
Without auto-layout you can try something like that:

Resources