1

I tried all the ways but its not as per my aspectations please help. I have to change the color of all * to red. I know I have to work in didload event. I tried to get the last character of all the strings and do one by one but it makes the code quite lengthy hope there would be any should code/ approach.

Thanks Image Here Please have a look

enter image description here

Ivan Barayev
  • 2,035
  • 5
  • 24
  • 30
raj
  • 93
  • 1
  • 9
  • 1
    if you change the place holder color try this http://stackoverflow.com/questions/21074417/change-of-uitextfield-placeholder-color – sohil Jan 10 '17 at 06:10
  • OP don't to change all placeholders color bro, he wants to change the color of only one letter in the placeholder... @sohil – Suraj Sukale Jan 10 '17 at 06:16
  • Yes, @raj, take a look for that question. You can change color of * character using attributed string. – kelin Jan 10 '17 at 06:17
  • @sohil sir please have a look to image also, as I have to change the color of only the * to red and rest of the placeholder text to remain same as black. – raj Jan 10 '17 at 06:17
  • @kelin sir I tried but using the attributed string I am confused a lot, could you help by doing it for one field only. Thanks – raj Jan 10 '17 at 06:27

3 Answers3

2

Try this one

NSMutableAttributedString *placeHoldertString = [[NSMutableAttributedString alloc] init];
    NSAttributedString *str1 = [[NSAttributedString alloc] initWithString:@"First Name" attributes:@{ NSForegroundColorAttributeName : [UIColor lightGrayColor] }];

    NSAttributedString *str2 = [[NSAttributedString alloc] initWithString:@"*" attributes:@{ NSForegroundColorAttributeName : [UIColor redColor] }];

    [placeHoldertString appendAttributedString:str1];
    [placeHoldertString appendAttributedString:str2];

    yourTextFeild.attributedPlaceholder = placeHoldertString;
user6788419
  • 7,196
  • 1
  • 16
  • 28
1

your question is still not clear you could make the textfield red on two events 1). when the user is entering the characters and jumps to the next textField you can make it red if the input is blank or incorrect 2). You can make it red on button click of submit or anything you want

and instead of writing it in View did load write it in UitextField Delegate method i.e Should change character in range method this will be called for each text field and you can use nested if else for your text field inside that method e.g

if textField == (your textfiled name here)
{
   //do your logic here for making the field red
} 

remember you have to use this nested if else in should change character in length method UitextField Delegate

Lucky
  • 41
  • 6
0

Try this

textField.attributedPlaceholder =
[[NSAttributedString alloc] initWithString:@"yourPlaceHolderName" attributes:@{NSForegroundColorAttributeName: yourColor, NSFontAttributeName : yourFont}];
    }
Dishant Rajput
  • 1,329
  • 1
  • 10
  • 20