UITextView autogrowing with new line inside UITableViewCell - ios

I have a textview as shown in the picture below,
I have given auto-layout constraint as top and bottom to thin line and leading to label and trailing to superview. Now whenever the return key is pressed the bounds of the textview automatically changes disobeying the constraints and the views get garbled as shown in picture below,
I don't want this behaviour, Please help, thanks!.

You can use following example for growing textview.
https://github.com/MatejBalantic/MBAutoGrowingTextView

Give a height constraint to you UITextView

Related

Why doesnt my textview show up when I add autolayout constraints?

I have a view which contains a textview (which displays a question) at the top. And 4 labels (for various answer options) with a stack of option buttons at the foot.
When leave the 'question' textview without constraints it appears fine in portrait. When I rotate the handset the text doesnt expand across the width of the screen.
I thought the way to resolve this was to click the add constraints pin/align button and click the T bars adding '0' constraints for top trailing and leading.
However when I do that the textview doesn't display at all. Any idea why?
The height constraint is missing. When you don't provide any constraints to your UITextView Xcode automatically will add the constraint's but as soon as you try to pin the top, leading and trailing anchors Xcode will not add any constraint's automatically.
You have to pin the bottom anchor of the UITextView to any of your buttons or give it a height constraint will solve your problem. Because UITextView will not calculate it's height based on it's inner content size like UILabel or UITextField.
If you want to only display some text and no edit functionality then you can use a UILabel and set the number of lines to 0.

UILabel keeps resizing to a height of 0 regardless of the text

I have a UILabel with the following constraints
and I set the number of Lines equal to 0. The layout on IB can be seen below. I want this UILabel to expand dynamically based on the text that I receive where the views below it get pushed down based on the height of the UILabel. However, that is not what happens.
As seen below, the UILabel doesn't appear at all. It seems to have a height of 0 regardless of what I set the text to be. Does anyone know what I need to modify to make this happen? Does anyone know why the UILabel has a height of 0?
UPDATES:
Things I tried given the comments below.
word wrap, nothing changed
adding a height constraint on UILabel, text gets cut off after the first line
height constraint with greater than or equal to constant, text still gets cut off after the first line
I created a dummy View according to your requirement.
Button has fixed constraints : leading width ,height, top space.
For label : leading, trailing, topSpace to button
3.For View below the label: give leading, trailing, height , top space to label
so here label height is not fixed .so it will change according to text.
After setting the text in label try out "labelName.sizeToFit()" this will automatically adjust the height of your label.
You should try to set a height constraint to your Label.
Considering the information you provided, it seems like it doesn't have enough height because you are using bottom constraint to the view under it. Rearrange your constraints or give a height constraint to the UILabel.
Select the UILabel,Set the Line Breaks mode is Word Wrap and set the number of lines is 0, example is given below,
And set the Height Constraints, If you set height contraints then select the UILabel, see the right side, select show the size Inspector --> Double click the height Contraints --> Relation --> set the Greater Than or Equal, its automatically expand the label, example is given below,
hope its helpful

How to wrap a UILabel within a prototype cell

I have a Table View with the following Prototype Cell:
I want the text of the UILabel labeled "Description" to wrap onto a new line if the texts exceeds the UILabel's width.
The UILabel has the following Attributes:
However, it doesn't work...Any help is appreciated.
Adjust the bottom constraint on the label, it is causing the label to have a fixed height that is hiding any wrapped lines. Everything else is fine.
There can be 2 issues in you auto layout constraints
If u have given fixed height to Description label then it can create problem
Secondly if u have given fixed height to image and bottom constraint to that image then also your label will not take the desired height
Please check this 2 constraint and let me know if u need any help

Move element when UITextView expands

I am trying to make a TextView in my scrollview look like the "Hoshi" TextField in this github repo raulriera TextFieldEffects
If I only have a textview with top/left/right constraint it will expand when I enter more text which is right.
But when I add a UIView under it, it will cut off the text if I enter alot of characters, what I want to do is to move the view/line under it along with the textview when it expands.
My constrains for the UIView is top space to textview >= 10 I thought that would move the View when the textview expands but nothing happens, instead the text gets cut off and the view wont move
Here is a image for the constraint:
So how can I make the view move once the textview expands?
Programmatically change the height constraint of the textview based on the text entered.
Remove the bottom constraints of the lable it will work as desired.That bottom constraints don't allow your lable to move down as your textView height increases.
I found a solution.
I had to set the UIView's bottom constraint to be >= low priority (250). That would make it expand together with the textview

UITextView text alignment

After the show segue from UITableView to UITextView
I have the following problem:
If i clear constraints for the UITextView the result is, of course unsatisfied:
But the good part of this – is starting from the first line at the top.
If I try to add suggested constraints to the UITextView I got this:
The problem is that the text begins not from the start.
What I need to get after segue page with text aligned to top like this:
You can add your own constraints to bottom bar.
first you need to place your textview up the bottom bar
Then add your own constraint to bar(drug with right button from textview on tabor).
Add vertical spacing
Then add other missing constraints
Result:
I believe embedding the textView in a scrollView will fix the issue and allow for the viewing of all the text.

Resources