Placing PlaceHolder In TextField

拈花ヽ惹草 提交于 2019-12-11 18:07:01

问题


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


回答1:


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.




回答2:


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




回答3:


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"];


来源:https://stackoverflow.com/questions/20423541/placing-placeholder-in-textfield

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!