Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You might as well use the UITextFieldDelegate methods (IMHO, easier to maintain than key-value observers):</p> <pre><code>#pragma mark - #pragma mark UITextFieldDelegate methods - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { _field.background = [UIImage imageNamed:@"focus.png"]; return YES; } - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { _field.background = [UIImage imageNamed:@"nofocus.png"]; return YES; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return YES; } </code></pre> <p>This only works when the UITextField.borderStyle property is of any type but UITextBorderStyleRoundedRect (in that case, the background property is not taken into account). This means you might use the code above with UITextBorderStyleBezel, UITextBorderStyleLine and UITextBorderStyleNone, as explained in the borderStyle documentation:</p> <blockquote> <p>borderStyle </p> <p>The border style used by the text field.</p> <p>@property(nonatomic) UITextBorderStyle borderStyle </p> <p>Discussion</p> <p>The default value for this property is UITextBorderStyleNone. If a custom background image is set, this property is ignored.</p> </blockquote> <p>This is the documentation for the background property of UITextField:</p> <blockquote> <p>background</p> <p>The image that represents the background appearance of the text field when it is enabled.</p> <p>@property(nonatomic, retain) UIImage *background</p> <p>Discussion</p> <p>When set, the image referred to by this property replaces the standard appearance controlled by the borderStyle property. Background images are drawn in the border rectangle portion of the image. Images you use for the text field’s background should be able to stretch to fit.</p> </blockquote>
 

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