I want to add mandatory field mark in textfield placeholder text like below image please suggest me i am totally confused how to do it
Asked
Active
Viewed 271 times
3 Answers
6
You can use :
NSMutableAttributedString *attriButedString = [[NSMutableAttributedString alloc]initWithString:@"Mandatory*"];
[attriButedString addAttribute:NSForegroundColorAttributeName
value:[NSColor lightGrayColor]
range:NSMakeRange(0, 9)];
[attriButedString addAttribute:NSForegroundColorAttributeName
value:[NSColor redColor]
range:NSMakeRange(9, 1)];
[[self.textField cell] setPlaceholderAttributedString:attriButedString];
This will look like as:
Note: Instead of hard-coded range you can calculate according to your stringlength.

Anoop Vaidya
- 46,283
- 15
- 111
- 140
0
If you are creating TextField from xib click on text field and go to attribute inspecter and fill your placeholder name in placeholder text feild

Gajendra Rawat
- 3,673
- 2
- 19
- 36
-
in that case you have to make your textfeild programmitically http://stackoverflow.com/questions/3482346/how-do-you-use-nsattributedstring chek this this will help you – Gajendra Rawat Dec 06 '13 at 12:27
-
no yaar. You need to color the placeholderString, as in another answer. – Anoop Vaidya Dec 06 '13 at 12:28
0
Try with this.....
[tfSubject setValue:[UIColor colorWithRed:249.0/255.0 green:204.0/255.0 blue:88.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];

Pradhyuman sinh
- 3,936
- 1
- 23
- 38