TextField height not automatically updated - ios

I have made a TableView, in which I set
self.tableView.estimatedRowHeight = 120.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
In one cell, I place a view, in which I drag a label, and for that label, I set constraints to top and bottom equal to view top and bottom. I increase the font of the label to 150. The table view cell scales nicely.
In the second cell, I place a view, in which I drag a textfield, and for that textfield, I set constraints to top and bottom equal to view top and bottom. I increase the font of the textfield to 150. The table view cell does not scale nicely, but keeps as small as my estimated row height.
How is this possible? Which properties should I set additionally for the textfield?
I am using iOS 9.0 as Deployment target. Below are a screenshot of the constraints and a screenshot of the simulator how it currently looks like.

Tableview does grow with textfield. You might not be setting correct font family.
In cellForRowAtIndexPath
[cell.yourTextField setFont:[UIFont fontWithName:#"HelveticaNeue" size:120]];
The cell height increased:
Try this and let me know if it worked. I played a lot with it.
Hope this can help.

Related

UITableview Height is not adjusting using UITableViewAutomaticDimension

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.

Set minimum height of table view cell?

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.

Self sizing cell with multiple labels does not show multiline label

I'm having three labels in my static table view cell and the middle label should be a multiline one.
I'm setting these two lines in viewDidLoad()
self.tableView.estimatedRowHeight = 130.0
self.tableView.rowHeight = UITableViewAutomaticDimension
The storyboard looks like this
Here are the constraints for each subview
Top label, middle label, bottom label, button
I've also set the number of lines for the middle label to 0. However it only shows one single line, instead of multiple lines. I guess it must have something to do with content hugging or content compression priorities or it's because my I'm using a UITableViewController with static cells.
UPDATE
If I change Vertical Compression Resistance Priority of the middle label to 751 and Vertical Content Hugging Priority to 250, the label shows multilines, but the cell does not get resized, so the top and the bottom label are outside the cell now.
UPDATE 2
I've just created a sample project and it turned out that it works with dynamic cells as expected but not with static cells. You can download the sample project here: https://dl.dropboxusercontent.com/u/67692950/ResizingCell.zip
I cloned your sample project. I think the problem is that you don't need to set UITableViewCell's height.
This is the one simple solution.
・To set Row Height "Default" in Table View Cell.(Unchecked Custom)
In this case, it works.
Download the sample project that I implemented here:
https://www.dropbox.com/s/w8q6ov9qjfxu1l3/ResizingCell.zip?dl=0
But the other way is that you calculate UITableViewCell's height from UILabel's height.
If you customize cell more complicatedly, it is better to isolate cell as a Custom cell.
Firstly, open storyboard, set your tableview row height to be 100, uncheck custom row height for the tableview cell, which value is currently 100.
Secondly, like #DBoyer said, call layoutIfNeeded. If you see "Unable to simultaneously satisfy constraints, Will attempt to recover by breaking constraint X", lower X's priority to 999. I think the warnings may have something to do with that when you get the cell, cell frame is CGRectZero.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
cell.layoutIfNeeded()
return cell
}
You need to either call layoutIfNeeded on the cell after setting the text of the multiline label or set the labels preferredMaxLayoutWidth
Use aspectRatio constraint for labels. Its puspose is to change width aswell as height according to need.This will help

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.

Overlapping elements of storyboard

The following code updates the Label in my prototype cell. However when the content takes up multiple lines, the UIImageView below the Label overlaps with it. I have uploaded pics of the storyboard and when the content is updated. How can I ensure that there is a fixed space between the last line of the Label and the UIImageView? I was under the impression that the spacing to nearest neighbor constraint would solve this but it seems to fix the spacing between the UIImageView and the first line of the Label.
contentText.numberOfLines = 0;
contentText.lineBreakMode = NSLineBreakByWordWrapping;
contentText.text = text;
[contentText sizeToFit];
You need to setup vertical spacing constraint between the label and imageView.
Select your label and imageView(the one overlapped) and then in Xcode
Select Editor->Pin->Vertical Spacing
This would ensure vertical spacing between them.Now as your label would resize according to text the imageView would not overlap instead would maintain a fixed amount of space from the label's last line.

Resources