How to add UIButton inside UITextView in ios? - 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.

Related

UILabel is penetrating through UIView content which is on top

I have UIView (popupView) which I'm adding it to another UIView (superView). This superView contains an UILabel with some text in it. Now this UILabel's text is disturbing the popupView content. For better understanding, you can check the attached screenshot (If you check screenshot, you can observe the line in the popup view was breaking with backside UILabels content). Please help me what went wrong in this or do I need to enable any property for UIView or UILabel.

How to set UIButton which has title and an image to change the width, according to localisation

I have following button configured.
and this is how I configured it. it works fine with English.
I have setup localisation with my app and when new text load to button it looks like below
Note : I have setup fixed width constraint using autolayout for the button and relation to
Greater than or equal.
how to fix this. hope your help with this.
Handling Insets for having button and image displayed together is a pain to adjust. A more common approach would be:
Create a custom view
Add an image and label giving appropriate constraints within the custom view
Put a button on top with clear background color so as to make it transparent.
All the three views can should be children of the custom view.
Now using this custom view, you have the flexibility to adjust it as per your needs.
Hope this helps :)
You can fix this issue by adding a new UIImageView as a subview to the super-view of the UIButton and set the image. Add the constraints leading(to the trailing of UIButton), centreY(to centerY of UIButton), height and width(constant you like) constraint to the UIButton that you already have. And add a UITapGestureRecognizer and set the action provided for UIButton.

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

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.

Resources