Change the placeholder text and image in the text box. The text box occupies the text image.
To achieve this effect, click the corresponding text to highlight the placeholder text, while other text boxes do not highlight the corresponding code.
# Import <UIKit/UIKit. h> @ interface XMGTextField: UITextField/** color */@ property (nonatomic, strong) UIColor * placeholderColor; @ end # import "XMGTextField. h "# import <objc/runtime. h> static NSString * const XMGPacerholderColorKeyPath = @ "_ placeholderLabel. textColor "; @ implementation XMGTextField //-(void) drawPlaceholderInRect :( CGRect) rect {// [self. placeholder drawInRect: CGRectMake (0, 10, rect. size. width, 25) withAttributes: @ {NSForegroundColorAttributeName: [UIColor grayColor], // NSFontAttributeName: self. font //}]; //}/*** Runtime (Runtime): an official C language library of Apple can perform many low-level operations (such as accessing hidden member variables \ member methods) */-(void) awakeFromNib {// set the cursor color to be consistent with the text color self. tintColor = self. textColor; // not the first responder [self resignFirstResponder];}/*** if the current text box loses focus, it will call */-(BOOL) resignFirstResponder {// modify the placeholder text color [self setValue: [UIColor grayColor] forKeyPath: XMGPacerholderColorKeyPath]; return [super resignFirstResponder];} /*** the focus of the current text box will be called */-(BOOL) becomeFirstResponder {[self setValue: self. textColor forKeyPath: placeholder]; return [super becomeFirstResponder];}-(void) setPlaceholderColor :( UIColor *) placeholderColor {_ placeholderColor = placeholderColor; // modify the placeholder text color [self setValue: placeholderColor forKeyPath: XMGPacerholderColorKeyPath];} @ end