Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UITextField占位符颜色更改单触_C#_Ios_Xamarin.ios_Uitextfield_Placeholder - Fatal编程技术网

C# UITextField占位符颜色更改单触

C# UITextField占位符颜色更改单触,c#,ios,xamarin.ios,uitextfield,placeholder,C#,Ios,Xamarin.ios,Uitextfield,Placeholder,因此,我一直在尝试更改UItextfield占位符的颜色,但没有成功。我尝试过子分类,也尝试过修改属性字符串,但没有任何效果,希望有人能帮我 这是我累的子类 public class CustomTextbox : UITextField { private string placeholder{ get; set; } public CustomTextbox () { } public CustomTextbox(string theString)

因此,我一直在尝试更改
UItextfield
占位符的颜色,但没有成功。我尝试过子分类,也尝试过修改属性字符串,但没有任何效果,希望有人能帮我

这是我累的子类

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); } }


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

var textat = new NSMutableAttributedString ("Email", new CTStringAttributes () {


            ForegroundColor = UIColor.White.CGColor,StrokeColor = UIColor.White.CGColor,
            StrokeWidth = 5.0f
        });
        this.emailtextbox.AttributedPlaceholder = textat;
有人能帮我吗。高级版谢谢。

试试这个:

[yourtextField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];

只需简化您已有的内容:-) 这在iOS7上起作用:

var t = new UITextField()
{
  AttributedPlaceholder = new NSAttributedString("some placeholder text", null, UIColor.Red)
}

monotuch的方法是(找到答案)


这是ObjC。尽管它很容易翻译成C#,但值得一提的是,非常感谢。这对我有帮助。我忘了NSAttributeString设置了所有参数,只需要前3个参数,剩下的参数可以设置为null。感谢再次出现相同的问题和相同的解决方案不知道为什么,但已修复!如果您只想更改占位符的颜色,而不想为文本创建字符串,该怎么办?有没有一种方法可以使用相同的NSAttributedString对象,但只是将第一个参数置零?我不明白您为什么要这样做。如果没有文本,为什么要设置它的颜色?这完全有效,我不知道为什么我没有尝试。谢谢
myLogin.AttributedPlaceholder = new NSAttributedString (
    "Enter your credentials",
    font: UIFont.FromName ("HoeflerText-Regular", 24.0f),
    foregroundColor: UIColor.Red,
    strokeWidth: 4 
);