Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I don't think you get built-in support for text shadows here, the way you do with <code>UILabel</code>.</p> <p>Two ideas:</p> <p>(1) <em>[Moderately tricky to code.]</em> Add a second <code>UITextField</code> behind the original, at a very small offset (maybe by (0.2,0.8)? ). You can listen to every text change key-by-key by implementing the <code>textField:shouldChangeCharactersInRange:replacementString:</code> method in the <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html#//apple_ref/occ/intf/UITextFieldDelegate" rel="noreferrer"><code>UITextFieldDelegate</code></a> protocol. Using that, you can update the lower text simultaneously. You could also make the lower text (the shadow text) gray, and even slightly blurry using the fact that fractionally-offset text rects appear blurry. <strong>Added:</strong> Oh yea, don't forget to set the top text field's background color to <code>[UIColor clearColor]</code> if you go with this idea.</p> <p>(2) <em>[Even more fun to code.]</em> Subclass <code>UITextField</code> and override the <code>drawRect:</code> method. I haven't done this before, so I'll mention up front that this depends on this being the designated drawing method, and it may turn out that you have to override another drawing function, such as <a href="http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/occ/instm/UITextField/drawTextInRect:" rel="noreferrer"><code>drawTextInRect:</code></a>, which is specific to <code>UITextField</code>. Now set up the drawing context to draw shadows via <a href="http://developer.apple.com/iPhone/library/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_shadows/dq_shadows.html#//apple_ref/doc/uid/TP30001066-CH208-TPXREF101" rel="noreferrer">the <code>CGContextSetShadow</code> functions</a>, and call <code>[super drawRect:rect];</code>. Hopefully that works -- in case the original <code>UITextField</code> code clears the drawing context's shadow parameters, that idea is hosed, and you'll have to write the whole drawing code yourself, which I anti-recommend because of all the extras that come with <code>UITextFields</code> like copy-and-paste and kanji input in Japanese.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload