/// <summary> /// Handles the Element Changed messages /// </summary> /// <param name="e">The e.</param> protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { base.OnElementChanged(e); if (this.Control != null && e.NewElement != null) { if (_helper == null) { _helper = new TextViewRenderHelper(Context); } if (_iconSpan == null) { _nativeLabel = (Android.Widget.TextView) this.Control; _iconLabel = (IconLabel)e.NewElement; //Set default value if (_iconLabel.IconSize == 0) { _iconLabel.IconSize = _iconLabel.FontSize; } _iconFont = _helper.TrySetFont("fontawesome-webfont.ttf"); _textFont = _iconLabel.Font.ToTypeface(); } SetText(); } }
/// <summary> /// Handles the Element Changed event messages /// </summary> /// <param name="e">The e.</param> protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e) { base.OnElementChanged(e); if (e.NewElement != null && this.Control != null) { if (_helper == null) { _helper = new TextViewRenderHelper(Context); } if (_iconSpan == null) { _nativeBtn = (Android.Widget.Button) this.Control; _iconButton = (IconButton)e.NewElement; _iconFont = _helper.TrySetFont("fontawesome-webfont.ttf"); _textFont = _iconButton.Font.ToTypeface(); _iconButton.IconSize = _iconButton.IconSize == 0 ? (float)_iconButton.FontSize : _iconButton.IconSize; var computedString = BuildRawTextString(); _iconSpan = BuildSpannableString(computedString); if (_iconButton.TextAlignement == Xamarin.Forms.TextAlignment.Center) { _nativeBtn.Gravity = Android.Views.GravityFlags.Center; } else if (_iconButton.TextAlignement == Xamarin.Forms.TextAlignment.End) { _nativeBtn.Gravity = Android.Views.GravityFlags.Right; } else if (_iconButton.TextAlignement == Xamarin.Forms.TextAlignment.Start) { _nativeBtn.Gravity = Android.Views.GravityFlags.Left; } _nativeBtn.TransformationMethod = null; _nativeBtn.SetPadding(0, 0, 0, 0); _nativeBtn.AfterTextChanged += nativeBtn_AfterTextChanged; } } }