ios - UITableViewCell does not fill the entire width of the table - ios

I think the cells don't fill the parent width because of indicated dimensions 300x300, but I don't know how to change it to parent size.
TableView has constraints on the boundaries of the device. I also tried set constraints for the cell but it didn't help.

You should set constraints in your image and on entire UITableViewCell xib just like in ViewController

This is a very basic design task. You really should take the time to go through a few tutorials on Auto-Layout.
The comment you posted: "Adding constraints in the UITableViewCell xib is not possible for me," along with the image, indicates you are selecting the Content View in your cell xib, but that is not where you want to add constraints.
You need to constrain the elements in your cell to the content view:
which results in a table view (at run-time) that looks like this:

Related

Tableview in scrollview when tableview content size increase then textview just below the tableview goes up to the tableview

I have Viewcontroller in which I set the scrollview. In the scrollview I have tableview which is in the Container and just below the container I have an textview and some other UIViews when I set the tableview frame size equal to content size and tableview scroll property false so that only scrollview scrolls when the content size increase the textview goes up to tableview and I want that when tableview content increase then textview also goes down and parent view frame size increase and decrease as the content size
This look like a job for a UICollectionViewController. If you want to take a look here
you can get a better understanding of what they are and how to use them.
Basically you want to put each of those UITableViews, UILabels and the UIButtons in it's own cell(buttons need to be arranged) of the collectionView then the cell with the buttons try to use a stack view with the image. This will automatically set the different sections apart from each other. I know the idea of a collectionViewCell containing a tableView may seem weird but check this out
Another solution is to get crazy with constraints and autoLayout. I don't recommend this route because autoLayout will make decisions on it's own if the exact layout is not explicitly declared. Basically you'll set the constraints by pinning the tableView and labels to each other and the container they are in.
Checkout Apple's docs here
Good luck and let me know how it goes
I would recommend using a xib (if storyboards is your preference) or programmatically embed a tableview in the Scrollview Controller. Set a default cell height and then calculate the height of the Tableview by grabbing the amount of cells (which you'll normally get from .count in an array).
Afterwards, constrain the top, left, and right constraints of the tableview to its parent. You can imbed these in a scroll view for ease. Then if you want default text underneath it, all you have to do is constrain the top of the textview to the bottom of the tableview.
Do the cell for the button's. As the post above said, buttons might be best done in a CollectionView, so you can either create a default cell (xib again is useful) or use a prototype cell in storyboard. Collection views are the same principle as tableviews when it comes to populating data, they are just formatted differently and insets/spacing between cells.
This should help!

UITableviewCell Dynamic Height Programmatically with the use of UITableViewAutomaticDimension

Hi Guys here i am suffering issue of dynamic height of UITableview Programmatically. I have set Autolayout of all view without any error
but lblDesc (UILabel) not expand with its size according to content. plz guide me
sometimes I do not need btnVideo (UIButton) so i have to hide btnVideo(UIButton) and dynamically all social networks UIButton come after lblDesc (UILabel)
Here i attached my code with only one view
UITableViewAutomaticDimension
https://drive.google.com/file/d/0B5mabdphYDhzWG9UMzM2MTV6cms/view?usp=sharing
You should use UITextView instead of UILabel.
Btw, never forget you setup constraints between text view and container views for all edges correctly, so according to your text size, the whole cell will be resized dynamically.
I have reviewed your code. tableview has correct setting.
Just setup correct layout constraints so that table view could know how it should change the height of cell.
Cheers

UITableView resize cell based on content

Hi I need help with understanding how to resize cell based on its content.
So first of all of course I found many links:
iOS: Multi-line UILabel in Auto Layout
https://www.youtube.com/watch?v=CkvZEJ7dIfw
https://github.com/williamhqs/GSTableViewDynamicHeight
As we said about git example (last link) I can't understand how to change some label and make it works. For example if I delete UILabel and create new one and bind it with content property (content - it is IBOutlet property of bottom label). I seems lost some setting and cell won't stretch.
So I think I don't know to much understanding how to do it.
What I want to understand:
How to setup auto layouts in the storyboard or programmatically.
Which thing I should handle programmatically to make it done.
How the preferred size affects on label. Do we need every time use bonds of superview as a preferred size?
Also in the git example we have one label that changes itself size. What if we have 2 UILabels with dynamic content how to setup it?
If you have some links or videos please drop them here, because I really stuck. Thank you!
I know it's duplicated question but I can't understand how to setup it.
To make Self Sizing Cells works there is three steps:
Setup correctly the constraints of the cell (most important the top and bottom constraints)
Specify the estimatedRowHeight of your table view
Set the rowHeight of your table view to UITableViewAutomaticDimension
for step 2 and 3 it's so easy just add these two lines in you viewDidLoad method
tableView.estimatedRowHeight = 44.0 // or whatever you want
tableView.rowHeight = UITableViewAutomaticDimension
for step 1 which is the most important part of self sizing process
what you need to keep in mind is that "self-sizing needs to get its size from your constraints."
Basically we need to make sure that top space and bottom space constraints of our cell is correctly set up here is an example :
just two labels with the constraints top,bottom,right and left space to each other and to container (see image) the UILabels Lines property is 0 so that you allow have multiple lines
Another example from a project that I am working on:
bottom line:
The label constraints should push against the size of the table view cell and make it taller. So always check the top and bottom constraints.
Also you may run intro trouble working with UILabel with multi-lines because
The intrinsic content size of UILabel and NSTextField is ambiguous for
multi-line text.
so make sure always to setup the preferredMaxLayoutWidth property of yout label:
- (void)layoutSubviews
{
[super layoutSubviews];
self.contentLabel.preferredMaxLayoutWidth = self.contentLabel.frame.size.width;
}
for more infrmation about this issue here read :
iOS Autolayout multi line UILabel
iOS multi-line UILabel in Auto-layout
preferredMaxLayoutWidth
And for more information about Dynamic Table View Cell Height in general here is some useful resources:
UITableView Tutorial: Dynamic Table View Cell Height
Understanding Self Sizing Cells and Dynamic Type in iOS 8
Self Sizing Table View Cells
Mysteries of Auto Layout, Part 1 (wwdc 2015)
Not sure if it will apply to AutoLayout, although when laying out a cell programmatically, running "layoutIfNeeded()" fixed my cell content stretch issue.
layoutIfNeeded was ran at the end of a configure method, used to map values (view model) to UI objects (views)

Change height of UIView inside of UITableViewCell (Storyboards)

I'm trying to create a master UITableViewCell with storyboards. The idea is that this cell contains all the possible subviews, but not all will be shown depending on the data for each cell.
I calculate the appropriate height for each cell depending on the data using the heightForRowAtIndexPath and this is working fine.
What I'm trying to figure out is how to adjust the height of subviews to zero inside the tableViewCell to effectively hide those elements while still respecting the relative constraints I set up (unlike removing the subviews from the superview which messes up all my constraints).
So basically I can't seem to figure out how to update the height(frame) of a subview (UIView) inside a UITableViewCell using storyboards and autolayout.
Any guidance would be awesome, and please let me know if I'm not using the best paradigm or thought process for the desired effect.
Best,
emjoseph
You'll need to use NSLayoutConstraint's. If your cell subviews do not already have fixed heights, you'll need to add them.
Once you've added those constraints, create references to your header file for those constraints. To do this, double click the height constraint so that it reveals itself in your ViewController structure, then control click and drag into your header file.
When you've decided which view to collapse, access your newly declared NSLayoutConstraint and edit the constant value.
Example:
subviewHeight.constant = 0;

Content of UITableViewCell falling outside of cell

I've been fiddling around for a bit to try and get this to work but for some reason I can't get the content in this tableView to stay inside the cell.
The following image is a screenshot of my storyboard where I define the tableView. You can see that there is amble space.
But then in the simulator you can see that the content is leaking out of the cell into other cells.
If I scroll then the cells crop the text but do not grow in height.
Not sure what kind of information will help out with this.
I have constraints added to the cells defining height, not width, as well as trailing edges and tops of the cells. Nothing crazy that should be causing this.
I'm defining the row height in the storyboard as such:
Define your row height from your TableView attributes inspector and uncheck the "Custom" option in your UITableViewCell as you show above.

Resources