问题描述
我已经在自定义EntryRenderer中重写了OnElementChanged方法,如下所示:
I've overridden OnElementChanged method inside a custom EntryRenderer which looks like this:
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);
}
}
我要做的就是自定义Entry控件,在左侧添加FontAwesome图标,并在底部添加一个图层,使其看起来只有底部边框.
All I want to do is customize Entry control to add FontAwesome icon on the left and add a layer at the bottom to make it look like it only has bottom-border.
问题在于Control.Frame
没有Width
& Height
(其值为0).
The problem is that Control.Frame
doesn't have Width
& Height
(their value is 0).
是否有其他帮助或其他方法来破解边框底部条目(UITextField)样式?预先感谢.
Any help or another way to hack border bottom Entry (UITextField) style?Thanks in advance.
推荐答案
使用添加为控件的Subview
的彩色UIView
,剪辑将为您处理.
Use a colored UIView
added as Subview
of the control and the clipping will be handled for you.
:-)
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);
}
这篇关于在CustomRenderer(Xamarin.Forms iOS)中获取控件的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!