I have a weird behaviour that has only shown up in the last week. I don't use IB, all the controls are created in code.
I have a text field with a keyboard active. The first time I load the text field and use the keyboard, everything works normally. The second time I use it, the typed text does not show in the text field. However, the text is in the text field programmatically. For example, I can use it to execute a search. When the keyboard closes, the text appears.
Some of my UITextFields have misaligned text. For example, I write "hello", and instead of displaying centered inside the field like normal, it displays shifted several pixels downward to the extent that the bottom of the text is cut off. It's almost as if another view is chopping the bottom off the text by obscuring it.
I use three20, but according to http://groups.google.com/group/three20/browse_thread/thread/d7c4bc1ee2f9590d#, Xcode is suspected of causing the problem. I seen the behavior on 2 diferent macs, one running with Snow Leopard (10.6) and the other with Leopard (10.5).
This is how the problem looks in Xcode:
It is not obvious, but there is text in that search field. Notice that the placeholder text is not show. However, if I hit Search, the code executes with the entered text.
This is how the app appears in the simulator:
I finally find the reason.
I call [textField becomeFirstResponder] in a function called from loadView. But I move it to viewDidAppear and everything work Ok...
I've seen that happen with text fields and affine transforms. If you rotate a text field using a transform, the text shows up in a seemingly random part of the superview. If you use a transform to move the text field to make room for the keyboard, you might be seperating the embedded text editor from the field itself. That would also explain why the text is in the code because the text attribute of the text field is not affected by the visual layout of the UI.
Related
I need to display a text message on screen.
Currently I am doing this with a Text view on a transparent window, so the text is overlayed on the screen, perfectly.
The issue is that if am working on a text editor, or Excel, the popup shows up it blocks the text editor by an invisible rectangle around the text, i am unable to send mouse clicks or text keys to the window that i was working on.
I know there are ways to do it, some applications already do it, I just need to know how.
Take a look at this question. It is in Objective-C but the API details you need are there, you just need to do the equivalent in Swift. Whereas that answer draws a transparent red border you will draw your text transparent.
Editing UITextField in tvOS shows a new view where the user can enter in text, and when text entry is done, the user is returned to the previous view. However, I have found that when I return from the text editor, the text I edit does not show up in my text fields. What's going on?
tvOS version 9.1
The reason why it isn't working is because the UITextField is using a non-default background color. Apparently in tvOS, the background color is rendered to the layer after the text has been rendered (Interestingly enough, this does not affect placeholder text). This also happens in interface builder. A bug report has been sent to Apple.
I had a similar issue with shared iOS/tvOS code where the next textfield placeholder text disappeared and became unresponsive.
Make sure that you are NOT setting textField.endEditing(true)
I have a table with several textFields in several cells, each with different input keyboards (numeric for phone number, standard for name, etc.).
When I change the editing text field by selecting one when other is editing, I want the first text field to hide the keyboard (the one which is being used) and only then the new keyboard to appear.
But putting [textField resignFirstResponder] doesn't solve my problem (the new one appears without the other disappearing, making the animation unnoticeable).
I tried to put the thread sleeping, but it didn't work as I wished.
Is there a way to have this animation?
Thanks a lot.
I want to create my own number pad to appear after user focus the textfield, so I have two question about it?
1.I use "Interface Builder to add a textfield in my view and select the "Number Pad" as the default pad for user to input number, so when I click the textfield, the number pad appear automaticlly, how can I stop it appear the number pad? because I want to show my number pad.
2.If I custom a view with number button inside it, how can I detect the event when I click the textfield? and whether after I detect the event I add a subview to show my custom number pad or not?
thanks
If you are creating a custom number pad (I assume this means a view with a grid of buttons), don't bother using a UITextField; there is no easy way to hide the native keyboard and, for all that trouble, there is nothing useful that the text field gives you.
I recommend creating a custom UIControl subclass. You can detect a touch inside the view and show your custom keypad that way. The documentation explains this pretty well.
I have a partial answer but not an ideal one, and I haven't tried this myself. Take a look at the documentation for the UITextFieldDelegate protocol.
You could have your controller set textField.delegate = self, then have it implement textFieldShouldBeginEditing to show your specialized keyboard somehow and then return NO so that it doesn't go into edit mode. When you tell your special keyboard to show itself, pass it a reference to the text field so it knows where to insert characters. The problem is that this probably won't show a cursor and won't let the user move the cursor to insert characters, etc.
So really this a bit ugly, but it may be sufficient. AFAIK there is no good way to do this :(
I have spent a few days trying to get around the limitations with UITextField, namely no text wrap and number of lines. I have created a UILabel, which is used to display the text entered in UITextField and does all the formatting stuff properly. The UITextField is hidden and the user sees all the text entered only in UILabel as it's being entered.
Everything is working perfectly except for the lack of a cursor on the UILabel to show the user where the next character typed into the field will show up.
I have experimented with using various characters as cursors on the label. But there is no getting around the fact that it is not the standard blinking cursor indicator on the iPhone and so the whole thing just looks wrong.
Before I abandon ship and go for a UITextView (with its own set of issues) I was wondering if anyone has any ideas as to how a blinking cursor can be added to the text field on a label text.
Thanks in advance.
Your approach has other issues which make it worth rethinking the strategy.
How does selection look like?
copy + paste?
Do you handle right to left languages?
Auto correction?
The list is certainly longer, but I think it's enough to consider other solutions. But I agree that all of UIKit's text handling is a bit poor.
If you don't need to support selection, copy and paste, and only need multiline input, you could use a | character and animate it as if it were blinking... either that or perhaps a custom overlay view on top of the label, that would implement the cursor drawing, animation and positioning based on the length of the string and the font used.
– sizeWithFont:forWidth:lineBreakMode:
– sizeWithFont:constrainedToSize:
– sizeWithFont:constrainedToSize:lineBreakMode:
– sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:
may help to achieve just that.
So what are the issues preventing you from going to a UITextView? It seems possibly easier to address those.