我正在尝试将 UITextField 的占位符文本设置为不同的颜色。我了解到我需要继承并覆盖 drawPlaceholderInRect 方法。
iPhone UITextField - 更改占位符文本颜色
(void) drawPlaceholderInRect:(CGRect)rect {
[[UIColor blueColor] setFill];
[[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:16]];
}
这是我到目前为止所拥有的,但我只是不知道如何让它恰到好处。我对最后一行感到困惑,因为我不知道如何将其映射到 MonoTouch/C# 对象。
using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Drawing;
namespace MyApp
{
[Register("CustomUITextField")]
public class CustomUITextField:UITextField
{
public CustomUITextField () :base()
{
}
public CustomUITextField (IntPtr handle) :base(handle)
{
}
public override void DrawPlaceholder (RectangleF rect)
{
UIColor col = new UIColor(0,0,255.0,0.7);
col.SetFill();
//Not sure what to put here
base.DrawPlaceholder (rect);}
}
}