protected override void OnElementChanged(ElementChangedEventArgs <Button> e)
        {
            if (Element == null)
            {
                return;
            }

            _extendedButton = Element as ExtendedButton;

            if (_extendedButton.IsCustomButton)
            {
                SetNativeControl(UIButton.FromType(UIButtonType.Custom));

                base.Control.TouchUpInside += (sender, _) =>
                {
                    ((IButtonController)Element)?.SendClicked();
                };
                base.OnElementChanged(e);
            }
            else
            {
                base.OnElementChanged(e);
            }

            SetStyle();
        }
        /// <summary>
        /// Adds individual action buttons to the alert view.
        /// </summary>
        /// <param name="action">Action.</param>
        public void AddAction(AdvancedActionSheetAction action)
        {
            var ExtendedButton = new ExtendedButton()
            {
                Style   = AdvancedActionSheetStyles.StandardButtonStyle,
                Command = new Command(async() =>
                {
                    await Navigation.PopPopupAsync();
                    action.Command?.Execute(null);
                }),

                CustomFont = action.Font,
                Text       = action.Title
            };

            if (action.ActionType == ActionType.Cancel)
            {
                CancelButtonVisible = true;
                CancelText          = action.Title;
                CancelFont          = action.Font;
                CancelCommand       = new Command(() =>
                {
                    action.Command?.Execute(null);
                });

                OnPropertyChanged(nameof(CancelButtonVisible));
                OnPropertyChanged(nameof(CancelCommand));
                OnPropertyChanged(nameof(CancelText));
                OnPropertyChanged(nameof(CancelFont));
            }
            else
            {
                buttonStack.Children.Add(ExtendedButton);
            }
        }
 private void SetPressedBackgroundColor(ExtendedButton extendedButton)
 {
     if (extendedButton.PressedBackgroundColor != Color.Default)
     {
         var pressed = UIColorExtensions.GetImageFromColor(extendedButton.PressedBackgroundColor.ToUIColor());
         this.Control.SetBackgroundImage(pressed, UIControlState.Highlighted);
         this.Control.SetBackgroundImage(pressed, UIControlState.Selected);
         this.Control.ClipsToBounds = true;
     }
 }
Exemplo n.º 4
0
        protected override void OnAttached()
        {
            _ExtendedButton = Element as ExtendedButton;

            _ExtendedButton.OnTouchesMoved      += HandleTouchesMoved;
            _ExtendedButton.OnTouchesBegan      += HandleTouchesBegan;
            _ExtendedButton.OnTouchesEnded      += HandleTouchesEnded;
            _ExtendedButton.OnDidLayoutSubviews += ExtendedButton_OnDidLayoutSubviews;

            CreateFillView();
        }
 private void SetDisabledBackgroundColor(ExtendedButton extendedButton)
 {
     if (extendedButton.DisabledBackgroundColor != Color.Default)
     {
         var disabled = UIColorExtensions.GetImageFromColor(extendedButton.DisabledBackgroundColor.ToUIColor());
         if (extendedButton.BackgroundColor != Color.Transparent)
         {
             this.Control.Layer.BorderColor = UIColor.Clear.CGColor;
         }
         this.Control.SetBackgroundImage(disabled, UIControlState.Disabled);
     }
 }
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            _extendedButton = Element as ExtendedButton;

            if (_extendedButton != null)
            {
                if (e.PropertyName == Button.TextProperty.PropertyName ||
                    e.PropertyName == ExtendedButton.CustomFontProperty.PropertyName ||
                    e.PropertyName == ExtendedButton.PressedCustomFontProperty.PropertyName ||
                    e.PropertyName == ExtendedLabel.CustomFontProperty.PropertyName ||
                    e.PropertyName == ExtendedButton.ImageVisibleProperty.PropertyName)
                {
                    SetFont();
                }

                if (e.PropertyName == ExtendedButton.HorizontalContentAlignmentProperty.PropertyName ||
                    e.PropertyName == ExtendedButton.VerticalContentAlignmentProperty.PropertyName ||
                    e.PropertyName == ExtendedButton.ContentPaddingProperty.PropertyName)
                {
                    SetContentAlignment();
                }

                if (e.PropertyName == Button.ImageProperty.PropertyName ||
                    e.PropertyName == ExtendedButton.ImageRightAlignedProperty.PropertyName ||
                    e.PropertyName == ExtendedButton.ImageHorizontalOffsetProperty.PropertyName)
                {
                    SetImage();
                }

                if (e.PropertyName == ExtendedButton.PressedBackgroundColorProperty.PropertyName)
                {
                    SetPressedBackgroundColor(_extendedButton);
                }

                if (e.PropertyName == ExtendedButton.DisabledBackgroundColorProperty.PropertyName)
                {
                    SetDisabledBackgroundColor(_extendedButton);
                }
            }
        }