UITextView text alignment - ios

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.

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.

UITextView autogrowing with new line inside UITableViewCell

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

Add view under text view

I have a fullsceen textView including much strings, so height of this view automatically changes. Its works nice, but i need to create some newView under this textView.
If I just make constraints like bottom of screen = bottom of newView, top of newView = bottom of textView, so newView will overlap textView.
try add height constraints to your textView with priority is 750.
Now you can build your app and run it again!
Goodluck
Just add your text view to the new view.
Here you are adding view with same size of textview. So it will over lapping. But if you add your text view subview of view so your main view will go back and text view will come front.
I think the problem is your views are trying to fulfil their constraints on fixed screen size.
If you want to keep it on one page (no scrolling) you can either add height constraints to your text view such that its height won't go over certain value or set the bottom view's constraint priority higher so that even when the textview expand it won't overrule bottom view's constraint.
Otherwise you might want to add ScrollView underneath your views. This way when your textview expands the bottom view will get pushed to the bottom outside the screen and you can scroll down the page

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

How to add UIButton inside UITextView in ios?

I'm getting stuck how to put UIButton inside UITextView on bototm right side, there is one more requirement when user type in textview the text doesn't overlap on button. Below images is my requirement. How can I achieve this?Thanks
You can add UIButton inside UITextview programmatically.
textview.addsubview(button)
What you can do is put the UIButton/UIView below the UITextView in the storyboard. Since elements placed in storyboard are w.r.t Z axis. Something like this
Then give bottom and trailing constraint only so that the position of the UIView remains the same even if the UITextView is growing in height dynamically
I think you need to put the textView then place a View on top of the textView and then add the button inside the View.

Resources