views:

1215

answers:

3

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 formating stuff properly. The UITextField is hidden and the user sees all the texted 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 bilinking cursor can be added to the text field on a label text.

Thanks in advance.

A: 

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.

Nikolai Ruhe
The main issue with UITextView is the UITouch issues with trying to let the user move the text field around the screen when they are done typing (Copy+paste takes over when the view gets the touch). UITextField does not have the same issues but can not have multiple lines. Auto correction, etc works just fine with a hidden UItextField and UILabel as the display. Just the cursor is the last hurdle.
cameron
A: 

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.

luvieere
This could be the solution. I will give it a shot and post the results. Thank you very much for the suggestions.
cameron
A: 

So what are the issues preventing you from going to a UITextView? It seems possibly easier to address those.

Kendall Helmstetter Gelner
Trying to trap touchesbegan and touchesmoved proved to be not as straight forward as I thought because of the copy+paste methods responding to the touch events before my app gets notified. I need to let the users move the text filed up or down the screen and place it where they want to. As soon as the text view is touched the copy+paste logic takes over and that's the end of my app's involvement in the events that follow!
cameron