Placing PlaceHolder In TextField

2019-09-16 03:18发布

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

enter image description here

3条回答
成全新的幸福
2楼-- · 2019-09-16 04:00

enter image description here

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

查看更多
Melony?
3楼-- · 2019-09-16 04:02

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:

enter image description here

Note: Instead of hard-coded range you can calculate according to your stringlength.

查看更多
成全新的幸福
4楼-- · 2019-09-16 04:02

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"];
查看更多
登录 后发表回答