Scrolling in TextView - ios

I have a UITextView with Scrolling Enabled.
My problem is that the TextView is small, width for two lines, adding successive lines the scroll does not appear to move around the TextView.
In short, I need to know how to implement the "scroll" according to the TextView grows.
Thank you!

If there are more content in text view with respect to size of text view then by
yourTextView.scrollEnabled = YES;
will scroll add the scrolling behaviour in your text view.
But if your text view's content is equal or less than to your text view's size then there is no need to scroll the text.

By default the TextView scrolls in vertical direction. So, when your content inside TextView will become more than its frame.height, it will automatically allow you to scroll vertically.

Related

Move textview of variable height when keyboard appears

I've a VC with few views above textfield and a button below text view contained inside scroll view. I'm trying to move textview up when keyboard is shown but I can't get it working correctly.
Textview height <=100 in IB. I'm adjusting textview height as we type in it up to max 120 then it scrolls.
I've read it and tried most of solution provided on Move textfield when keyboard appears swift
The problem I'm facing is bottom constraints, if I set it then my textview stretches in height when it loads and then it breaks textview height adjustment during typing. And I can't find any working solution without setting bottom constraints.
Can anyone give me some pointers on how to fix this issue?
Add fixed text view height and set bottom constraints to greater than or equal to.

Scrollview doesn't scroll with multiline label in it

I have a multiline label inside a scrollview. I set up the content size, let's say to scrollView.contentSize.height = 2000
But the view doesn't scroll. There is barely any code in the project. What is going wrong?
The only thing is that I don't have constrain for the height of the label, because it will vary depending on the length of text.
It doesn't matter about the height. But what does matter is that you need to pin it to the bottom of the scroll view also.
By pinning it on the top and bottom it will use the label to set the content size and so allow it to scroll.
I suggest to add a UITableView instead of UIScrollView, adding one UITableViewcell that contains a UILabel. By setting the appropriate values of:
Label's constraints.
tableView's rowHeight.
tableView's estimatedRowHeight.
It should works fine for your case.
For more Information about setting a dynamic cell height, you might want to check this answer.
Hope that helped.

Enable scroll view scroll if text view is long

I have a scrollView which contains textView. If text is long and does not fit on a screen, I would like to increase textView height (which I think I could do by adding NSLayoutConstraint outlet and modifying it, correct me if I am wrong) so that view would be scrollable (or non scrollable) depending on text length.
Pretty much, like I can set Scrolling Enabled for textView, except I wan to scroll whole view because of images and labels I have on that view.
EDIT. Basically - how to guess textView height based on string, in order to have proper size textView
To make your scrollview content scrollable you need to set the size of your UIScrollView content ( your textview ), e.g. use:
scrollView.contentSize = CGSizeMake(textview.frame.size.width, textview.frame.size.height)

Dynamic Label in Swift, doesn't Scroll

I'm Learning Swift, and I want to figure out how I can scroll the UILabel
I have a Label that is populated dynamically , But the text goes under the bottom bar.
I tried with 0 Lines, Constraints.. I'd like to scroll the view for read whole text
UPDATE
After the answers I have this situation
With Textview I Can read all my text, using the scroll
With UIScrollbar and UILabel, I can't read all my Text.
When I have to use TextView instead of UIScrollBar+UiLabel?
Alternatively, you can replace UILabel with UITextView.
Then set textView.editable = false.
Add the UILabel into a UIScrollView. Set the content size according to the size of the UILabel.
You can also use a scrollview, if you have more than one control to scroll together. For example you have an image on top and a description below and you want to scroll them together, you can use a UIScrollView. Just put the image view and UILabel inside the scrollview.
If its just text you want to scroll, you can use a UITextView.

UITextView horizontal scrolling

I have a UITextView which wrapping words of long text and it have a vertical scrolling functionality.
How can I switch off the word wrap, and switch on the horizontal scrolling with keep the vertical scrolling?
i have seen this answer in stackoverflow only..
Let's say I want a scrollable width of 600 and a visible width of 250.
The first step is to make the UITextView a wide as the area you want to be scrollable. So what you would have put into contentSize, in this case 600.
Then the right inset is set to the difference between the actual width and the width you wanted. In this case 350.
This way cursor is restrained to the width you need BUT there is text visible to the right of your desired width, after all, the UITextView IS 600 pixels wide.
Now here's where the really hackish bit comes in, don't read on if you're sensitive or have a weak stomach.
Get an image of the user interface to the right where UITextView should end. Insert it into the NIB as an UIImage view and put it back in it's place, making sure that it's on top of the UITextView.
When the view is displayed, the cutout sits on top of the UITextView and hides the text overrun.

Resources