In my app, I have a UITextView. When I key in data in the UITextView, the words are not getting completely filled in the UITextview. There is a boundary within the UITextView and the words scroll up as I key in the words. Is there a setting which I am missing in UITextView. Please let me know. Please find the screenshot below
You can set a frame and a contentSize as it inherits from the UIScrollView to make it bigger. I do not have access to IDE right now but something like this should work:
myTextView.frame = CGRectMake(10,10,300,300);//example values
myTextView.contentSize = CGSizeMake(300,300);//example values
but sooner or later you want be able to see the whole text on the screen and you will need to scroll anyway.
You can also change this values while user is typing by using some delegate methods
Related
I have a UITextView. The text in the view keeps changing based on user action. On many occasions, the text is too large to fit and so my text view (which has a desired fixed width and height) scrolls the text. The control flow is something like this
1) user takes some action, and text view appears with some text (possibly more than what can fit, so comes with a scroll)
2) user dismisses the view (I simply hide the text view)
3) user takes another action, and text view appears with new text (i use UITextView setText to reassign the text, and simply turn the hidden property to NO)
My text cannot be edited by the user. It is always reset to a different string in code
Problem:
When the textview is redrawn/rendered with the new text, on some occassions the contentoffset.y AND bounds.origin.y values of the text view are set to something besides 0, which is not desirable. It is intermittent, but creates a major UI issue. At least I think those new values are what causes the UI to look so weird. Open to other suggestions here...
I want to know why this happens, and how to fix this? Since the text is changed programatically, I can't depend on textViewDidChange: to reset these values.
EDIT: This is how I am changingt he text everytime something new has to be placed in the textview
[textView1 setText:someNSString];
where someNSString is, well, some string with text
I am trying to create a textview that holds a 3 line string. As the user works, the string will update and become wider, the height (number of lines) will remain the same. Reading through the documentation I understand that the size of the container cannot change, it is readonly.
I have code that places text into the text property of a UITextView but it will not scroll the text right or left. I played around with inserting a UIView into the textview and believe that will work, but doesn’t seem like the way to about this. I’m kind of figuring that I need a custom UITextView class and a custom NSTextContainer. Wondering if the proper direction? Any help is appreciated.
Thanks,
Jeff
I can't understand how create something like this:
The idea is the UITextView is resizing. But how to resize it when user enter 100 rows? I need to check /n and then increment frame by lineHeight and frame of cell?
Suggest pls.
No need. The text view should be resized to fit the keyboard. After that it scrolls the text if there is more text than fits into the visible part.
The path of least resistance to getting what you're describing to work is to create a method that updates the frames of the UITextView and UIView when the keyboard goes up or down. You know when the keyboard goes up and down based on UIKeyboardWillShowNotification and UIKeyboardWillDisappearNotification. The notification contains a userInfo dictionary that specifies the y-coordinate of the keyboard with respect to your view controller's window. All you need to do is recalculate your frames subtracting the height of the keyboard (either something like 216 or 0). If you still have questions about this let me know, and I'd be happy to explain further.
I have a narrow UITextView (about 1 line in height) to which I only add text programmatically, setting the text property of it as I click buttons. I also handle the cursor position manually, setting the selectedRange as the text changes. All works great as long as I have only one line of text.
When I have two or more lines of text and try to insert text at the first line, the text is inserted correctly and the cursor position is still at the right place but the UITextView scrolls to the bottom. When I then add another piece of text at the top it scrolls up to the "correct" position. This pattern then repeats for every entered piece of text at a line other than the last, making the UITextView scroll up and down for every button pressed.
I also tried calling UITextView scrollRangeToVisible: passing the selectedRange property as argument after setting the new text. That didn't work either.
I finally tried setting selectedRange after a 0.5 s delay after I set the text. Then it works as it should, but only after the UITextView has first been scrolled down to the bottom for 0.5 s. This seems to indicate that the setText method of UITextView is asynchronous in some way, and completes after I have already set selectedRange or called scrollRangeToVisible, and readjusts the UITextView to what it believes is the desired.
Can anyone tell me what is going on, and how I can get around the problem.
Thanks!
The auto scroll behavior of UITextFields can be annoying and difficult to harness at times.
Do you need the user to manually edit the text? If not, use a multiline UILabel.
If yes, also use a multiline UILabel and exchange it on the fly against a UITextView once the user taps. Change it back on didEndEditing. This techniques has worked well for me in table views.
I solved the problem!
When starting in the maze of creating a custom input view, I began implementing UITextInput and I found that the UITextInput protocol declares many interesting methods. And what is awesome is that UITextView implements that protocol. So even though it's not in the immediate UITextView API reference, you can call all UITextInput methods on your UITextView. For instance insertText: (from UIKeyInput protocol) and replaceRange:withText:. They made it much more flexible to programmatically work with a UITextView. Hope this can help someone else too!
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.