首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PlaceHolder中放置TextField

在PlaceHolder中放置TextField
EN

Stack Overflow用户
提问于 2013-12-06 12:08:45
回答 3查看 268关注 0票数 0

我想在文本字段占位符文本中添加强制字段标记,如下图所示,请告诉我我完全搞不懂怎么做。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-12-06 12:11:31

您可以使用:

代码语言:javascript
复制
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];

如下所示:

注释:你可以根据你的字符串长度来计算,而不是硬编码的范围。

票数 6
EN

Stack Overflow用户

发布于 2013-12-06 12:15:13

如果要从xib创建TextField,请单击“文本”字段,转到属性检查器,然后在占位符文本feild中填写占位符名称。

票数 0
EN

Stack Overflow用户

发布于 2013-12-06 12:33:40

试试这个..。

代码语言:javascript
复制
 [tfSubject setValue:[UIColor colorWithRed:249.0/255.0 green:204.0/255.0 blue:88.0/255.0 alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20423541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档