@property (Nonatomic,copy) nsattributedstring *attributedplaceholder;Text propertiesNsmutabledictionary *attrs = [Nsmutabledictionary Dictionary];attrs[nsforegroundcolorattributename] = [Uicolor Graycolor];Nsattributedstring: Text with attributes (Rich Text technology) nsattributedstring *placeholder = [[Nsattributedstring alloc] initwithstring:@ "mobile phone number" attributes:attrs];Self. Phonefield. attributedplaceholder = placeholder; nsmutableattributedstring *placehoder = [[Nsmutableattributedstring alloc] initwithstring:@ "mobile phone number"]; [Placehoder setattributes:@{nsforegroundcolorattributename: [uicolor Whitecolor]} range:nsmakerange (0, 1)]; [Placehoder setattributes:@{nsforegroundcolorattributename: [uicolor Yellowcolor], nsfontattributename: [ Uifont systemfontofsize: +]} range:nsmakerange (1, 1)];[ Placehoder setattributes:@{nsforegroundcolorattributename: [uicolor Redcolor]} range:nsmakerange (2, 1 )]; Self . Phonefield. Attributedplaceholder = Placehoder;
- (void)drawPlaceholderInRect:(CGRect)rect{ [self.placeholder drawInRect:CGRectMake(0, 10, rect.size.width, 25) withAttributes:@{ NSForegroundColorAttributeName : [UIColor grayColor], NSFontAttributeName : self.font}];}
[self setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
Modification of the placeholder color of Uitextfield