Dynamic height with UITableViewAutomaticDimension - ios

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.

Related

Stretchable Header View in UITableView with dynamical height

How can I manage the height of the TableViewHeader based on the lines of an UILabel?
I followed this guide but I can't manage the header height dynamically.
In the guide it is fixed to a fixed size to which I tried to add the height of the label but it doesn't work.
I would prefer to use a tableview and not a scrollview as the data is populated dynamically.
I also tried to modify the constraints of the label dynamically, but when scroll the view of the label is stretched and not the image.
Add this in viewDidLoad:
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionHeaderHeight = 25;
After that just give correct constrains for the headerView . That's it! No need to implement heightForHeaderInSection

Capturing UIImageView bounds/frame size with TableViewCell autolayout

I am using the attached prototype cell layout in a tableview. Each cell is sized using autolayout:
tableView.rowHeight = UITableViewAutomaticDimension
The "tagline" is a string and sets the height of the cell depending on the length of the string. Given a greater length the height of the UIImageView also resizes. The ImageView is set to a variety to images with different sizes and aspect ratios. I would like to resize the image based on the beginning width of the ImageView(that does not change) and the resulting height and the image's aspect ratio.
The code to set the two is very straightforward.
cell.taglineLabel.text = tagline
cell.recipeImageView.image = image
Inside a tableView cellForRowAt function I set the tagline first in the code, then the Image. However, if I attempt to resize the image and I inspect the bounds or frame size, the size is the original size. I am assuming the autosize is performing after the func. Therefore, I cannot determine size.
Is there a way to force the autosize after the tagline is set, so I can see the frame/bounds sizes I have to work with?

UITableview cell height based on imageContent like facebook feed

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

Swift: Getting a Label in TableView Prototype Cell to display multiple lines (word wrap)

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.

Resize font of label in custom tableViewCell

So I have a custom table view cell and I want a label to be resized based on the text in it. I've already tried doing this in the cellForRowAtIndexPath method-
cell.titleLabel.adjustsFontSizeToFitWidth = YES;
cell.titleLabel.numberOfLines = 1;
[cell.titleLabel setMinimumScaleFactor:8.0/[UIFont labelFontSize]];
I also tried setting minimum scale factor and minimum font size in IB...but the label font doesn't resize.
The case I want to take care of is the case where the text in the label is larger than the phone width and so I want to resize when that happens.
What's going wrong/How do I achieve that?

Resources