Beispiel #1
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (Control is null || Element is null)
            {
                return;
            }

            if (e.PropertyName == VisualElement.HeightProperty.PropertyName ||
                e.PropertyName == VisualElement.WidthProperty.PropertyName ||
                e.PropertyName == IconAwesomeLabelBase.IconProperty.PropertyName ||
                e.PropertyName == IconAwesomeLabelBase.TextProperty.PropertyName ||
                e.PropertyName == IconAwesomeLabelBase.TypeIconProperty.PropertyName)
            {
                if (!string.IsNullOrEmpty(((IconAwesomeLabelBase)Element).Icon))
                {
                    Control.Font = UIFont.FromName(IconExtensions.FindNameForFont
                                                       (((IconAwesomeLabelBase)Element).TypeIcon), (nfloat)Element.FontSize);

                    IIcon icon = IconExtensions.FindIconForKey(((IconAwesomeLabelBase)Element).Icon);

                    Control.Text = $"{icon.Character}";
                }
            }
        }
Beispiel #2
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Label> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement == null)
            {
                //Only enable hardware accelleration on lollipop
                if ((int)Android.OS.Build.VERSION.SdkInt < 21)
                {
                    SetLayerType(LayerType.Software, null);
                }
            }

            if (!string.IsNullOrEmpty(((IconAwesomeLabelBase)Element).Icon))
            {
                Control.Typeface = Typeface.CreateFromAsset(context.Assets,
                                                            IconExtensions.FindNameFileForFont(((IconAwesomeLabelBase)Element).TypeIcon));

                IIcon icon = IconExtensions.FindIconForKey(((IconAwesomeLabelBase)Element).Icon);

                Element.Text = $"{icon.Character}";
            }
            else
            {
                Control.Typeface = Typeface.Create(Element.FontFamily, TypefaceStyle.Normal);
                Element.Text     = ((IconAwesomeLabelBase)Element).Text;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.Button> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement == null)
            {
                //Only enable hardware accelleration on lollipop
                if ((int)Android.OS.Build.VERSION.SdkInt < 21)
                {
                    SetLayerType(LayerType.Software, null);
                }
            }

            if (!string.IsNullOrEmpty(((IconAwesomeButtonBase)Element).Icon))
            {
                Control.Typeface = Typeface.CreateFromAsset(context.Assets,
                                                            IconExtensions.FindNameFileForFont(((IconAwesomeButtonBase)Element).TypeIcon));

                IIcon icon = IconExtensions.FindIconForKey(((IconAwesomeButtonBase)Element).Icon);

                Element.Text = $"{icon.Character}";
            }
            else
            {
                Control.Typeface = Typeface.Create(Element.FontFamily, TypefaceStyle.Normal);
                Element.Text     = ((IconAwesomeButtonBase)Element).Text;
            }

            if (((IconAwesomeButtonBase)Element).ImageSource != null)
            {
                Android.Widget.Button thisButton = Control as Android.Widget.Button;
                thisButton.Touch += (object sender, Android.Views.View.TouchEventArgs e2) =>
                {
                    if (e2.Event.Action == MotionEventActions.Down)
                    {
                        Control.SetBackgroundColor(Element.BackgroundColor.ToAndroid());
                    }
                    else if (e2.Event.Action == MotionEventActions.Up)
                    {
                        Control.SetBackgroundColor(Element.BackgroundColor.ToAndroid());
                        Control.SetShadowLayer(0, 0, 0, Android.Graphics.Color.Transparent);
                        Control.CallOnClick();
                    }
                };
            }
        }
Beispiel #4
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (Control is null || Element is null)
            {
                return;
            }

            if (e.PropertyName == VisualElement.HeightProperty.PropertyName ||
                e.PropertyName == VisualElement.WidthProperty.PropertyName ||
                e.PropertyName == IconAwesomeButtonBase.BorderColorProperty.PropertyName ||
                e.PropertyName == IconAwesomeButtonBase.BorderThicknessProperty.PropertyName ||
                e.PropertyName == IconAwesomeButtonBase.IconProperty.PropertyName ||
                e.PropertyName == IconAwesomeButtonBase.TextProperty.PropertyName ||
                e.PropertyName == IconAwesomeButtonBase.TypeIconProperty.PropertyName)
            {
                CreateCircle();

                if (!String.IsNullOrEmpty(((IconAwesomeButtonBase)Element).Icon))
                {
                    Control.Font = UIFont.FromName(IconExtensions.FindNameForFont
                                                       (((IconAwesomeButtonBase)Element).TypeIcon), (nfloat)Element.FontSize);

                    IIcon icon = IconExtensions.FindIconForKey(((IconAwesomeButtonBase)Element).Icon);

                    Control.SetTitle($"{icon.Character}", UIControlState.Normal);
                }
                else
                {
                    Control.Font = Font.OfSize(Element.FontFamily, Element.FontSize).WithAttributes(Element.FontAttributes).ToUIFont();
                    Control.TitleLabel.LineBreakMode = UILineBreakMode.WordWrap;
                    Control.TitleLabel.TextAlignment = UITextAlignment.Center;
                    Control.SetTitle(((IconAwesomeButtonBase)Element).Text, UIControlState.Normal);
                }
            }
        }