[英]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.