将PlaceHolder放置在TextField中 [英] Placing PlaceHolder In TextField

查看:175
本文介绍了将PlaceHolder放置在TextField中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在textfield占位符文本中添加强制字段标记,如下图所示,请告诉我,我完全感到困惑如何做到这一点

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

推荐答案

你可以使用:

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

这将如下所示:

注意:您可以根据您的stringlength计算硬编码范围。

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

这篇关于将PlaceHolder放置在TextField中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆