Dynamic Label in Swift, doesn't Scroll - ios

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.

Related

Make UITextView in UIScrollView right aligned

I have a UITableViewCell that i want to have a Title and a detail. The detail could be a long text so i am using a custom cell with a label as the title and a UITextView (Green rectangle) embedded in a UIScrollView as the detail.
I want the UITextView to be right aligned in the UIScrollView so it will look like this (assume the 'detail' is in a scrollView):
So far i have tried playing with several constraints but i can't get it to work.
textView.textAlignment = .right should do the trick.
However I don't think it's conventional to solve something like this problem by embedding a textView inside a scrollView. A textView has scrolling functionality enabled by default if its text height is greater than the textViews height. So best to remove the scrollView and just use a textView

iOS ImageView and TextView inside scrollView

I want to create this layout in which the image is at the top and scrolls along with textview, textview itself should not be scrollable but should expand with the text so that ImageView and textView are together in a single scrollView.
I'm not able to figure out the constraints and how to expand that text view.
The image shows the textview ending at the bottom of the screen because I have set it's scrollable property to off, I want the text to run down the screen ,textView to expand .I am ready to use stackViews as well if needed.
Thank you
You can achieve that by following these steps:
Create a tableView.
Add imageView as your tableView's tableHeaderView. (Use This Link) for more details).
Add only one row to tableView.
Add your textView to your row and add constraints as zero to contentView.
Set UITableViewAutomaticDimension as heightForRowAtIndexPath.
Also you don't need to use scrollView as tableView will do that for you.

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)

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.

Scrolling in TextView

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.

Resources