If we want to achieve this effect, click on the corresponding text, placeholder text display highlighting, and other text boxes are not highlighted by the corresponding code
#import<UIKit/UIKit.h>@interfaceXmgtextfield:uitextfield/** Color*/@property (nonatomic,strong) Uicolor*Placeholdercolor;@end#import "XMGTextField.h"#import<objc/runtime.h>StaticNSString *ConstXmgpacerholdercolorkeypath=@"_placeholderlabel.textcolor";@implementationXmgtextfield////-(void) Drawplaceholderinrect: (cgrect) rect{//[Self.placeholder drawinrect:cgrectmake (0, ten, rect.size.width,) withattributes:@{ Nsforegroundcolorattributename:[uicolor Graycolor],//NSFontAttributeName:self.font// }];//}/** Runtime: Apple's official C-language library can do a lot of low-level operations (such as accessing hidden member variables \ member methods)*/-(void) awakefromnib{//set the cursor color to match the text colorSelf.tintcolor=Self.textcolor; //No first responders .[self resignfirstresponder];}/** * The current text box loses focus is called*/-(BOOL) resignfirstresponder{//Modify placeholder text color[self Setvalue:[uicolor graycolor] Forkeypath:xmgpacerholdercolorkeypath]; return[Super Resignfirstresponder];}/** * The current text box gathers focus will be called*/-(BOOL) becomefirstresponder{[self setValue:self.textColor forkeypath:xmgpacerholdercolorkeypath]; return[Super Becomefirstresponder];}-(void) Setplaceholdercolor: (Uicolor *) placeholdercolor{_placeholdercolor=Placeholdercolor; //Modify placeholder text color[self Setvalue:placeholdercolor Forkeypath:xmgpacerholdercolorkeypath];}@end
Change settings text box placeholder text and pictures