UITextField PlaceHolder颜色变化Monotouch

pja*_*e15 3 c# placeholder uitextfield xamarin.ios ios

所以我一直试图改变UItextfield占位符的颜色,我没有运气.我已经尝试过子类,我尝试修改Attributed字符串,但没有任何作用,所以希望有人可以帮助我.

这是我厌倦的子类.

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


}
Run Code Online (Sandbox Code Playgroud)

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

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


            ForegroundColor = UIColor.White.CGColor,StrokeColor = UIColor.White.CGColor,
            StrokeWidth = 5.0f
        });
        this.emailtextbox.AttributedPlaceholder = textat;
Run Code Online (Sandbox Code Playgroud)

请有人帮助我.提前致谢.

Kru*_*lur 12

只是简化你已有的东西:-)这适用于iOS7:

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

  • 这完全有效,我不知道为什么我没有尝试.谢谢! (2认同)