Custom UITextField drawing while editing

I am trying to build a textbox with a custom prefix (think of a textbox to enter a phone number and the prefix is ​​the international dialing code). I would like the textbox to be very similar to a regular textbox and an unselectable prefix area. Moreover, I would like the prefix to move and be next to the text when entering a phone number. At the beginning, the prefix should simply be drawn from the placeholder text.

To achieve this, I subclass UITextField and override drawTextInRect and drawPlaceHolderTextInRect to draw a custom prefix in front of the text to be drawn. This works like a charm when the textbox is empty (drawPlaceHolderTextInRect is called) or when the textbox is not in edit mode (drawTextInRect is called). However, when the text box is in edit mode and not empty, none of these methods are called. Is there any other method that I can override to provide a custom drawing when the user enters a phone number in the text box?

+3
ios objective-c cocoa-touch uikit uitextfield


source to share


No one has answered this question yet

Check out similar questions:

1665
How can I get the UITextField to move upward when there is a keyboard - when starting editing?
1244
How can I sort NSMutableArray with custom objects in it?
768
Can I embed my own font in the iPhone app?
537
iPhone UITextField - change placeholder text color
464
Set the maximum character length of the UITextField
422
iOS - Disable keyboard on touch outside of UITextField
385
Text box for UITextField?
51
Resize the UITextField while typing (using Autolayout)
0
How to control editing UITextFields in a custom UITableViewCell
0
textRectForBounds: not called on custom UITextFields loaded from Nib



All Articles
Loading...
X
Show
Funny
Dev
Pics