Self. PassTF. AttributedPlaceholder = [self changePlaceholderWithTextField: self. PassTF withString: @ "please enter the password"].Copy the code
- (NSMutableAttributedString *)changePlaceholderWithTextField:(UITextField *)textField withString:(NSString *)string{ // Set the cursor color textField. TintColor = [UIColor whiteColor]; textField.textColor = [UIColor whiteColor]; TextField. LeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 42/2/1.5, 0)]; textField.leftViewMode = UITextFieldViewModeAlways; NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:string]; If (SCREEN_WIDTH = = 320) {[attributeString addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 12.0] range:NSMakeRange(0, string.length)]; } else {[attributeString addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 14.0] range: NSMakeRange (0, string.length)]; } / / set the placeholder font color [attributeString addAttribute: NSForegroundColorAttributeName value: [UIColor ColorWithRed :152/255.0 green:152/255.0 Blue :152/255.0 alpha:1] range:NSMakeRange(0, string.length)]; return attributeString; }Copy the code