Created
August 10, 2014 09:02
-
-
Save dymx101/fd26ac336942ed4307b7 to your computer and use it in GitHub Desktop.
Customize UITextField Clear Button Style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You'll need to create your own clear button image in this case. I would suggest taking a screenshot of the clear button and editing in photoshop. | |
You can take that image and create a UIButton with the image dimensions. From there you can set it as the UITextField's rightView. Like so: | |
================================================================ | |
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; | |
[button setImage:[UIImage imageNamed:@"clear_button.png"] forState:UIControlStateNormal]; | |
[button setFrame:CGRectMake(0.0f, 0.0f, 15.0f, 15.0f)]; // Required for iOS7 | |
theTextField.rightView = button; | |
theTextField.rightViewMode = UITextFieldViewModeWhileEditing; | |
================================================================ | |
I typed that without syntax checking and what not so you'll want to check it out before running it. You'll also want to replace clear_button.png with whatever your image name is. | |
You'll also need to write your own method to clear the text field. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment