我一直试图改变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;发布于 2014-05-12 13:36:42
只需简化你已经拥有的。这适用于iOS7:
var t = new UITextField()
{
AttributedPlaceholder = new NSAttributedString("some placeholder text", null, UIColor.Red)
}发布于 2016-02-04 02:51:47
这样做的单调方法是(答案是找到这里)
myLogin.AttributedPlaceholder = new NSAttributedString (
"Enter your credentials",
font: UIFont.FromName ("HoeflerText-Regular", 24.0f),
foregroundColor: UIColor.Red,
strokeWidth: 4
);发布于 2014-05-12 13:07:42
试试这个:
[yourtextField setValue:[UIColor blueColor] forKeyPath:@"_placeholderLabel.textColor"];https://stackoverflow.com/questions/23609689
复制相似问题