I have an EntryRenderer that updates the border color on UITextFields. Initially, it sets the border color to blue and when the IsError property is changed, it sets the border to either red or blue based on the result.
When the page is loaded, the border color does not get set at all but on the subsequence property changed, the borders are updated with the right color.
Here's the code. Anybody experiences similar issue?
[assembly: ExportRenderer (typeof (QuarcEntry), typeof (QuarcEntryRenderer))]
namespace Quarc.Mobile.iOS.Views.CustomRenderers
{
public class QuarcEntryRenderer : EntryRenderer
{
UIView _topBorder;
UIView _bottomBorder;
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged (sender, e);
if (e.PropertyName == QuarcEntry.IsErrorProperty.PropertyName)
{
InitSubViews();
var el = (QuarcEntry)Element;
var color = (el.IsError
? el.BorderColorOnError.ToUIColor ()
: el.BorderColor.ToUIColor ());
SetBorderColor (color);
}
}
protected override void OnElementChanged (ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged (e);
if (e.OldElement == null)
{
InitSubViews();
Control.BorderStyle = UITextBorderStyle.None;
}
}
void InitSubViews()
{
var nativeTextField = Control;
var defaultColor = ((QuarcEntry)Element).BorderColor.ToUIColor ();
_topBorder = new UIView { BackgroundColor = defaultColor };
_topBorder.Frame = new Rectangle (0, 0, nativeTextField.Frame.Size.Width, 1.0f).ToRectangleF();
_bottomBorder = new UIView { BackgroundColor = defaultColor };
_bottomBorder.Frame = new Rectangle(0, nativeTextField.Frame.Y + nativeTextField.Frame.Size.Height - 1.0f, nativeTextField.Frame.Size.Width, 1.0f).ToRectangleF();
nativeTextField.AddSubviews (new [] { _topBorder, _bottomBorder });
}
void SetBorderColor(UIColor color)
{
_topBorder.BackgroundColor = color;
_bottomBorder.BackgroundColor = color;
}
}
}
Here's the image of the page when it first loads. The text boxes are without border even though the subviews have already been added during OnElementChanged.
Here's the image of the page after the IsError property is changed.
Any help would be appreciated.
Thanks,
Chai