UITextField占位符颜色更改Monotouch
本文关键字:Monotouch 颜色 占位符 UITextField | 更新日期: 2023-09-27 18:03:07
我一直试图改变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;
简化你已有的。
var t = new UITextField()
{
AttributedPlaceholder = new NSAttributedString("some placeholder text", null, UIColor.Red)
}
单触的方法是(答案在这里找到)
myLogin.AttributedPlaceholder = new NSAttributedString (
"Enter your credentials",
font: UIFont.FromName ("HoeflerText-Regular", 24.0f),
foregroundColor: UIColor.Red,
strokeWidth: 4
);
试试这个:
[yourtextField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];