c# - NSAttributedString 不适用于 UITextField ios xamarin

标签 c# ios xamarin.ios xamarin

我在更改 UITextField 内占位符的字体和字体大小时遇到​​问题。

this.emailTextField = new UITextField ();

//Not working
this.emailTextField.AttributedPlaceholder = new NSAttributedString ("Email address", UIFont.FromName("Didot-Italic", 6.0f));

this.emailTextField.KeyboardType = UIKeyboardType.EmailAddress;
this.emailTextField.ReturnKeyType = UIReturnKeyType.Next;
this.emailTextField.AdjustsFontSizeToFitWidth = true;
this.emailTextField.ClearButtonMode = UITextFieldViewMode.Always;
this.emailTextField.BackgroundColor = UIColor.White;
this.emailTextField.BorderStyle = UITextBorderStyle.None;

var bottomLayer = new CALayer ();
bottomLayer.BorderColor = UIColor.Black.CGColor;
bottomLayer.BorderWidth = 1;
bottomLayer.Frame = new RectangleF (0, 29, 200, 1);

this.emailTextField.Layer.AddSublayer (bottomLayer);
this.emailTextField.Frame = new RectangleF (60, this.fbButton.Frame.Bottom + 20, 200, 30);

最佳答案

你可以尝试像下面这样使用它。到目前为止它对我有用。

this.emailTextField.AttributedPlaceholder = new NSAttributedString ("Email address", new UIStringAttributes{Font = UIFont.FromName("Didot-Italic", 6.0f)});

关于c# - NSAttributedString 不适用于 UITextField ios xamarin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28518760/

相关文章:

c# - MVC 中的动态下拉列表

C#:用XmlDocument解析XML时的行信息

ios - 将 UIView 保存为 xml

ipad - 适用于 iPad 的 MonoTouch : How to show another UIViewController in a UIPopoverController?

c# - xamarin.ios 使用仅图像代码实现 PageController

c# - 使用 NAudio 获取默认输出音频设备

c# - 如何使用 C# 在运行时创建类的新实例?

iphone - 延迟后不使用 NSThread 或 sleep() 执行方法 - 还有其他选择吗?

ios - 沿 MKPolyLineView 的渐变(MKPolylineRenderer)

c# - 如何在 iOS 上将文本字段居中?