首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITextField PlaceHolder变色单片

UITextField PlaceHolder变色单片
EN

Stack Overflow用户
提问于 2014-05-12 12:56:11
回答 3查看 5K关注 0票数 3

我一直试图改变UItextfield占位符的颜色,但我没有运气。我尝试过子类化,我尝试过修改属性化字符串,但是没有任何效果。

这是我试过的子类。

代码语言:javascript
复制
public class CustomTextbox : UITextField
{
    private string placeholder{ get;  set; }
    public CustomTextbox ()
    {
    }

    public CustomTextbox(string theString)
    {
        this.placeholder = theString;
    }

    public override void DrawPlaceholder (RectangleF rect) {
        using (UIFont font = UIFont.SystemFontOfSize (16)) 
        using (UIColor col = new UIColor (UIColor.Blue.CGColor)) { 
            col.SetFill (); col.SetStroke (); col.SetColor (); base.DrawString (base.Placeholder,rect, font); } }
            

}

这是我尝试过的属性字符串方法:

代码语言:javascript
复制
var textat = new NSMutableAttributedString ("Email", new CTStringAttributes () {

            
            ForegroundColor = UIColor.White.CGColor,StrokeColor = UIColor.White.CGColor,
            StrokeWidth = 5.0f
        });
        this.emailtextbox.AttributedPlaceholder = textat;
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-05-12 13:36:42

只需简化你已经拥有的。这适用于iOS7:

代码语言:javascript
复制
var t = new UITextField()
{
  AttributedPlaceholder = new NSAttributedString("some placeholder text", null, UIColor.Red)
}
票数 13
EN

Stack Overflow用户

发布于 2016-02-04 02:51:47

这样做的单调方法是(答案是找到这里)

代码语言:javascript
复制
myLogin.AttributedPlaceholder = new NSAttributedString (
    "Enter your credentials",
    font: UIFont.FromName ("HoeflerText-Regular", 24.0f),
    foregroundColor: UIColor.Red,
    strokeWidth: 4 
);
票数 0
EN

Stack Overflow用户

发布于 2014-05-12 13:07:42

试试这个:

代码语言:javascript
复制
[yourtextField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23609689

复制
相关文章

相似问题

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