Make UITextView in UIScrollView right aligned - ios

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

Related

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)

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.

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.

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