I am working on feed concept, where tableview cell height need to auto adjust after image downloading , current i am facing below issue
when you observe above image there are two labels just above the image , after downloading image labels are override by the imageview.
Actual feed should look like below
here i don't have height constraint for the imageview , because based on image content height will increase , for this i have applied aspect ratio for the imageview.
But after scrolling its working as expected.
please do help on this issue
Give Leading, Trailing, Top and Bottom Constraints for ImageView. Top constraint to "7 days ago" label. It may work for you.
Write below lines of code in viewDidLoad()
tableView.estimatedRowHeight = Your cell default height
tableView.rowHeight = UITableViewAutomaticDimension
Related
I have tableview inside tableview cell , I am using UITableViewAutomaticDimension in heightForRowAt, tableview height is not adjusting automatically. I have to calculate cell height manually.
Any idea ?
You are missing either bottom or top constraint.
Consider you have to add label in table cell, then you have give both top and bottom constraint to label (make line number 0).
It will automatically increase the size of table cell according to label text.
Don't forgot to set estimatedRowHeight.
To get automatic cell height work correctly you must hook all your constraints properly from top to bottom in the cell Xib , or if you're creating constraints in code , that's how auto-layout can calculate the height automatically
self.tableView.estimatedRowHeight = 50.0
self.tableView.rowHeight = UITableViewAutomaticDimension
Set all constraint like bottom, top, left, right.
I have a UITableView,In this table i have created as custom cell with image & label.I have given label leading,trailing,top,bottom.I want to set the size of label to increase according to text which is happening.I have used UITableAutomaticDimension & EstimatedRowHeight.Now i want to set minimum height of cell equal to height of image.Now if text is very less in label then height of image is decreased.Now i want to keep height cell minimum as image height & increase it when there is more text.Please help how can i do it?
Looking at the view you shared i would suggest the following constraints.
Top of UIImageView to top of your cell.
Left of UIImageView top left of your cell.
Width and Height constraints of your UIImageView.
Bottom of UIImageView to the bottom of your cell which will be greater than or equal to.
Right of your UIImageView to Left of your UILabel.
Top of your UILabel to top of your cell.
Right of your UILabel to right of your cell.
Bottom of your UILabel to bottom of your cell.
Adding these constraints should solve your problems.
I have a problem. I'm trying to implement dynamic cell height in the annex, when I have nothing. Normally, in my cell I have one UIImageview and three UILabel. My task is to implement dynamic height of the text without changing the picture size. The picture comes from the server and scaled inside the cell with the mod Scale to fill. My Text does not change its height in the cell.
self.tableView.estimatedRowHeight = 415.0f;
self.tableView.rowHeight = UITableViewAutomaticDimension;
I always found numberOfLines = 0;
The problem is that the picture is stretched to the server, which should not be a text of its size does not change.
The problem is that you have not placed any limiting constraints on the image view's size. Therefore it adopts the size of the image.
A lot of the solutions I've seen here include changing the cell's background to an image and using sections for rows rather than just rows themselves. I'm looking to have only two sections and have each cell expand in height on tap, so neither of those solutions would work.
I saw one solution includes setting the frame of the cell in the layoutSubviews() function like so:
override func layoutSubviews() {
super.layoutSubviews()
self.frame = CGRectOffset(self.frame, 0, 10);
}
When I do this however, it only gives margin to one cell and that's only when I tap on the cell.
Is there a surefire way to add spacing in between UITableViewCells without being hacky and breaking the cell layouts in the process?
I did this yesterday pretty easily with auto layout.
I set the background of the cell and it's content view to clear, then I created a new view and setup constraints all around it and put my labels inside of it. The height changes dynamically based on the label so I needed to use UITableViewAutomaticDimension for the row height and give it an estimated row height as well.
I don't see why this wouldn't work for expanding it on a tap as well, you just might have to reload the cell.
make the cell and it's contentView transparent
contentView addSubview customContentView and layout your cell on customContentView
customContentView pin to contentView top leading trailing with offset 0 but pin to bottom with offset 10 //the margin height
I'm trying to setup a tableview which each cell will have an Image on the left, a Label which overlays the image, and finally a label to the right of the image with long text in which I would like for it wrap to the next line if needed. My tableview row height is set at 65.
I have set the number of lines to 0 and set the line break to work wrap.
I even tried setting parameter programmatically in my CustomTableViewCell class:
self.materialLabel?.numberOfLines = 0
self.materialLabel.sizeToFit()
self.materialLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
I've tried many combinations of setting constraints on my label, but it either doesn't work or affects all objects in the cell with the image and image label out of sync. The alignment constraints are not available to set.
Working with Xcode 6.3.2, Swift 1.2, and iOS 8
Thanks in Advanced!
You can use dynamic cell height ( or self sizing cell).
Basically, you create top, leading, bottom, trailing label's constraints relative to cell's contentView.
and then set
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = someValue
http://www.raywenderlich.com/87975/dynamic-table-view-cell-height-ios-8-swift
There are many ways to setup dynamic height for table cell.
If your not not using autolayout, you need to calculate table size programmatically and return using table view delegate method.
If your using autolayout, your life will be very easy. Add constraints to cell, I.e add border, width and height constraints to image. Add only 4 border constraints to image(don't add height constraint). This may not be the exact constraints, but this will give you a idea. Add following code in viewDidload
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = someValue
This should work.
Turns out my label width was too wide. I had to anchor my imageview and the imagelabel and set the width and height before setting the constraints on my label.