我在自定义EntryRenderer中覆盖了OnElementChanged方法,如下所示:
Dim listOfValues AS List(Of String) = new List(Of String)
For Each item As ListItem In ddLokasi.Items
If item.Selected Then
listOfValues.Add(item.Value)
End If
Next
我想要做的就是自定义Entry控件以在左侧添加FontAwesome图标并在底部添加一个图层,使其看起来只有底边框。
问题是protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var iconLabel = new UILabel();
iconLabel.Font = FontAwesome.Font(12);
iconLabel.Text = " " + FontAwesome.FAPlay;
iconLabel.Frame = new CGRect(x: 5, y: 0, width: 20, height: 20);
Control.LeftView = iconLabel;
Control.LeftViewMode = UITextFieldViewMode.Always;
Control.BorderStyle = UITextBorderStyle.None;
var bottomLine = new CALayer();
bottomLine.Frame = new CGRect(0.0, Control.Frame.Height - 1, Control.Frame.Width, 1.0);
bottomLine.BackgroundColor = UIColor.White.CGColor;
Control.Layer.AddSublayer(bottomLine);
}
}
没有Control.Frame
&amp; Width
(他们的值为0)。
任何帮助或其他方式破解边框底部条目(UITextField)样式? 提前谢谢。
答案 0 :(得分:3)
我想要做的就是自定义Entry控件以在左侧添加FontAwesome图标并在底部添加一个图层,使其看起来只有底边框。
使用添加为控件UIView
的彩色Subview
,将为您处理裁剪。
: - )
if (Control != null) {
Control.BackgroundColor = UIColor.LightGray;
var iconLabel = new UILabel();
iconLabel.Font = FontAwesome.Font(12);
iconLabel.Text = " " + FontAwesome.FAAmbulance;
iconLabel.Frame = new CGRect(x: 5, y: 0, width: 20, height: 20);
Control.LeftView = iconLabel;
Control.LeftViewMode = UITextFieldViewMode.Always;
Control.BorderStyle = UITextBorderStyle.None;
Console.WriteLine ("cs: " + customSize);
UIView myBox = new UIView (new CGRect (0.0, 20.0, 1000.0, 1.0));
myBox.BackgroundColor = UIColor.Red;
Control.AddSubview(myBox);
}
if (Control != null) {
var iconLabel = new UILabel();
iconLabel.Font = FontAwesome.Font(12);
iconLabel.Text = " " + FontAwesome.FAPlay;
iconLabel.Frame = new CGRect(x: 5, y: 0, width: 20, height: 20);
Control.LeftView = iconLabel;
Control.LeftViewMode = UITextFieldViewMode.Always;
Control.BorderStyle = UITextBorderStyle.None;
Console.WriteLine ("cs: " + customSize);
UIView myBox = new UIView (new CGRect (0.0, 20.0, 1000.0, 1.0));
myBox.BackgroundColor = UIColor.Black;
Control.AddSubview(myBox);
}