UITextView scrollRangeToVisible make range visible appear at the top - ios

I am currently using UITextView. When I use scrollRangeToVisible it works but it brings the range to the bottom of the screen. How can I bring this range to the top of the screen. TLDR: UITextview method scrollRangeToVisible brings the characters of interest to bottom of view. I want it to come to top of view. How can I do this? Thank you

One approach is to:
find the bounding box of the range you want at the top
if it's below the current top line, add the height of the text view
then call .scrollRectToVisible()
You also need some error and bounds checking. I put together an extension you can try out if you wish: https://gist.github.com/DonMag/19daac863553c51725a56f0bc3296076

Related

Textfield Connecting and Labels

I have always had this problem and could never figure out how to solve it. My issue is that I want to produce a similar thing as the photo: Image
I want to be able to have text fields connect like this and be able to have a 'label' on the left while still being able to input on the right. Any help is greatly appreciated.
If I am not mistaken, I think that what you want is to have a label on the left and a textview on the right. The image you have supplied looks like the textViews and labels reside within a UITableView controller as static cells. What they have most likely have done here is simply extended the label from the left to the centre and the textview from the right to the centre, such that each takes up half the cell (and added constraints). Then you can set the text alignment to left for the label and right for the textview. The final thing you should do is get rid of the border of the textview, which can be found in the attributes inspector and is called Border Style. You want to set it to the far left option, like this:
As the background of the cell is white and the textview's also, you shouldn't need to change it, but if you do there is an attribute for that a bit further down that you can have a play with.

Horizontally scroll single line UITextView?

I need a view that allows me to have an editable method of text entry that is limited to one line, but can scroll horizontally. After a bit of research, I found that maybe a UITextView would work well.
This is going in a table view cell so I've tried putting this in awakeFromNib()
code.textContainer.maximumNumberOfLines = 1
code.layoutManager.textContainerChangedGeometry(code.textContainer)
but this is what happens (I'm repeating the same line to fill the text view)
So for attributes I need to assign, I need:
Disable Vertical scrolling
Enable Horizontal scrolling
Limit Text View to one line
If anyone also knows a better way to do this (maybe with a scrollable Text Field?) I would love to hear it.
Thanks in advance!

iOS: How to Detect subview position around view

I have a Label named "Lable_Match" (in self.view)
and a UIView(in self.view).
In that View there are 1000+ labels.
and view is move using touch move method. and When user move View and he touch end that time check view subview lable is on the "Lable_Match" if any one lable is on this so the check text are same or not.
I believe you want to use this method:
[self.view convertRect:self.label.frame fromView:self.view.subview];
from this post: How to get the frame of a view inside another view?
This will give you the adjusted position of the label form your list of 1000+ labels. You can then compare that to the label of Label_match , then compare their text
In response to your question my question is there any way to find the location of your label. If you have the fixed location for label then you can match current taped area and the label area and find the text. Or if you have a fixed sized label you can manipulate it and able to get the label text

UITextView won't scroll from outside particular area

I have a UITextView with approx 100 lines(for testing purpose its static) which scrolls fine but when i try to scroll from approx 150 its from the bottom i can not scroll. That means it lets me scroll from only certain area of the textview. for example see the image below. If i try to select and scroll above 3 line from top, i can scroll but below 3rd line, It won't let me scroll. I went through documentation but couldn't find anything that makes sense.
Try resizing the frame of your UITextView so it does not overlap the UITabBarView. If you create this in interface builder, you can resize it there.
if there is some area that is not taking ui touches, thAT means, your UITextView is being overlapped by another view. try:
[self.view bringSubviewToFront:textView];
also think about Enrico's answer.
Put Background color for TextView. It will give you extact idea of TextView Complete framing and is it sub view of background or foreground.

how to implement the autoresizing UITextView vertically?

First look at the screenshot:
second press the return button, the screenshot for your reference:
after four times click
return
button, the height of text field will not be higher any more.
now here is the question: how can I implement the function of textfield? and what about the background Image behind the text Field , should auto resize too? if there are any solution, let me know! thanks very much----
Make it UITextView not a text field, track the text changes at shouldChangeTextInRange of the textView delegate.
In this method calculate the number of lines (textView.contentSize.height/textView.font.lineHeight), compare it with the previous value to decide whether you need to proceed or just return. If the number of lines is changed, check whether the textView is already displaying the maximum number of lines (that must be 3 on the image) and based on the results you will change the textView, it's superview and a button frames (you can also make it animated easily) and probably scroll the text to the change region with scrollRangeToVisible.

Resources