[英]Xamarin iOS UITextField padding with Border Style None
我正在尝试向UITextField添加填充。 我做了一些研究,发现了以下代码。
UIView paddingView = new UIView(new RectangleF(0, 0, 5, 20));
txtBoxUsername.LeftView = paddingView;
txtBoxUsername.LeftViewMode = UITextFieldViewMode.Always;
这个代码工作正常,直到UITextField有一个边框。 我的UiTextField没有边框。 一旦我设置了Border None,这个填充效果也会丢失。 我用以下代码设置border none。
txtBoxUsername.BorderStyle = UITextBorderStyle.None;
任何人都可以告诉我如何添加填充到没有边框的UITextField。
以下代码为我工作
public class TextBox : UITextField
{
public TextBox(string placeholder, UIFont font = null)
{
Layer.BorderWidth = 0f;
AttributedPlaceholder = new NSAttributedString(
placeholder,
font: UIFont.ItalicSystemFontOfSize(15.0f)
);
if (font != null)
{
Font = font;
}
UIView paddingView = new UIView(new CGRect(0, 0, 10.0f, 20.0f));
LeftView = paddingView;
LeftViewMode = UITextFieldViewMode.Always;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.