Subclassing and overriding UITextField in Monotouch

前端 未结 1 839
挽巷
挽巷 2021-01-18 17:25

I am trying to set the placeholder text for a UITextField to a different color. I have learned that I need to subclass and override drawPlaceholderInRect method.

iP

相关标签:
1条回答
  • 2021-01-18 17:51

    The original ObjC code does not call super (it's base method) but drawInRect:. Have you tried the same with MonoTouch ? e.g.

    public override void DrawPlaceholder (RectangleF rect)
    {
        using (UIFont font = UIFont.SystemFontOfSize (16))
        using (UIColor col = new UIColor (0,0,255.0,0.7)) {
            col.SetFill ();
            base.DrawString (rect, font);
        }
    }
    

    Note: drawInRect:WithFont: maps to the DrawString extension method in C# (which can be called on any string).

    0 讨论(0)
提交回复
热议问题