I have a UITextField that is programmatically created. I face the problem where my last character is not shown if the text exceeds the length of the textfield.
How can I show the last character entered and shift the text to the left?
It all works perfectly fine for my other UITextFields created in storyboards. I couldn't find an answer for the question.
Also, it I need to use textField not textView because I would have to change a lot of things.
Thanks!
Related
Currently, I have a UITextField with an Add button at the end. The purpose of this textfield is for the user to enter word and for that word to be centered in a UILabel. Below is the visual :
I have the 3 UILabels embedded in a Stack View and each UILabel is hidden until user types something and presses Add button. Running simulator made me realize that if I keep one of them hidden it totally messes up the alignment of the other two. This is due to equal centering in the Stack View which made me question myself if this is right approach for what I want to achieve. I tried other distributions for the Stack View as well but no luck. Thoughts?
I have an UITextView inside a UIScrollView. The textView display correctly when text is not too long.
But when text is long long, it is not showing text in textView. However, the textView is still selectable.
Here is my layout.
Thank you so much!
I had the same problem displaying very long text (33745 chars) in a UITextView and after experimenting with different copy lengths the limitation is with the simulator. If the number of chars was over 7435 the simulator did not show the text but I could scroll, copy etc.
But testing on several devices, the 33745 chars text displayed correctly.
Just say
yourTextView.scrollEnabled = YES;
and see the magic
I am having a strange issue with a secure textfield in iOS7. It may seem a stupid detail, but I want to fix it.
It turns out I have two textfields, one to insert the username and the second one as an input for the user password. The thing is, when I insert text into the password field, the dots size becomes smaller, but when this secure textfield stops being the first responder, the size of the dots becomes the one it should be (bigger than when being the first responder).
As an ilustration, take a look at these two images extracted from my app:
Non first responder:
First responder:
As you can see, the size of the dots changes depending on whether the secure textfield is the first responder or not.
Is there any way to avoid this resizing?
Thank you all in advance.
Additional info:
I am using an external text font which seems to work fine on the textfields.
The text size of both textfields is 17.0.
Both font type and font size are set in the ViewDidLoad method of the ViewController where the textfields are.
I have a weird glitch that occurs when I press the delete key in an empty UITextField.
I shouldn't be able to delete anything but the cursor moves over to the left about a tab width in the text field when I hit delete and it is empty.
This only happens when I have the text centered in the text field, not when it is left justified.
When I resume typing it jumps back to the center and behaves normally.
Any idea what could be going on?
In 2018 on XCode 9.3, and IOS 10.3...
I have verified that... at least in my case, the problem was being caused by the text field containing placeholder text.
When I removed the placeholder text, the cursor behaved "normally" / as expected.
Even though this isn't a very popular question, I just created an account to share my discovery regarding this problem.
The glitch/bug you're experiencing is caused by one line of code that you have (probably) added to your UITextField. No, it is not due to your UITextField containing a placeholder like the other answer suggested.
To fix this problem, the line you'll need to remove is
textField.clearButtonMode = UITextFieldViewModeWhileEditing
Adding this line adds a clear button to the right side of your UITextField while it is being edited.
This causes your text to be shifted left by the size of the clear button, but only when the button is there (in this case, only while editing). This is why you may notice your text shifting back into the correct position when you have finished editing.
Hope this helps someone down the road!
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!