protected void SetupTitleLabelWithTitle(string title)
 {
     titleLabel = new UILabel();
     if (title != null)
     {
         titleLabel.TranslatesAutoresizingMaskIntoConstraints = false;
         titleLabel.Font      = UIFontExtensions.MontserratFontSemiBold(20);
         titleLabel.TextColor = UIColor.FromWhiteAlpha(white: 0.13f, alpha: 1.0f);
         titleLabel.Lines     = 0;
         titleLabel.Text      = title;
         containerView.AddSubview(titleLabel);
     }
 }
        protected void SetupButtonWithTitle(string title, BFPaperButton button, bool isStacked)
        {
            button.TranslatesAutoresizingMaskIntoConstraints = false;
            button.SetTitle(title.ToUpper(), UIControlState.Normal);
            button.SetTitleColor(NBConfig.AccentColor, UIControlState.Normal);
            button.IsRaised = false;
            if (button.TitleLabel != null)
            {
                button.TitleLabel.Font = UIFontExtensions.MontserratFontSemiBold(14);
            }
            if (isStacked)
            {
                //button.. = UIControlContentHorizontalAlignment.Right;
                button.ContentEdgeInsets = new UIEdgeInsets(0, 0, 0, 20);
            }
            else
            {
                button.ContentEdgeInsets = new UIEdgeInsets(0, 8, 0, 8);
            }

            containerView.AddSubview(button);
        }
Esempio n. 3
0
        public override NBMaterialDialog ShowDialog(NBDialogSettings settings)
        {
            _hideDialogOnTapOnOverlay = settings.HideDialogOnTapOnOverlay;
            _dialogHeight             = _pages[_currentPage].DialogHeight;
            isStacked = settings.StackedButtons;

            nfloat totalButtonTitleLength = 0.0f;

            windowView = settings.WindowView;

            var windowSize = windowView.Bounds;

            windowView.AddSubview(View);
            View.Frame         = windowView.Bounds;
            tappableView.Frame = View.Frame;
            tapGesture         = new UITapGestureRecognizer(TappedBg);
            tappableView.AddGestureRecognizer(tapGesture);

            SetupContainerView();
            // Add content to contentView
            contentView = _pages[_currentPage].View;
            SetupContentView();


            if (settings.Title != null)
            {
                SetupTitleLabelWithTitle(settings.Title);
            }

            if (settings.OkButtonTitle != null)
            {
                UIStringAttributes attribs = new UIStringAttributes {
                    Font = UIFontExtensions.MontserratFontSemiBold(14f)
                };
                totalButtonTitleLength += new NSString(settings.OkButtonTitle.ToUpper()).GetSizeUsingAttributes(attribs).Width + 8;
                if (settings.CancelButtonTitle != null)
                {
                    totalButtonTitleLength +=
                        new NSString(settings.CancelButtonTitle.ToUpper()).GetSizeUsingAttributes(attribs).Width + 8;
                }

                // Calculate if the combined button title lengths are longer than max allowed for this dialog, if so use stacked buttons.
                nfloat buttonTotalMaxLength = (windowSize.Width - (kWidthMargin * 2)) - 16 - 16 - 8;
                if (totalButtonTitleLength > buttonTotalMaxLength)
                {
                    isStacked = true;
                }
            }

            // Always display a close/ok button, but setting a title is optional.
            if (settings.OkButtonTitle != null)
            {
                if (okButton == null)
                {
                    okButton                = new BFPaperButton();
                    okButton.Tag            = 0;
                    okButton.TouchUpInside += (sender, args) => PressedAnyButton(sender as NSObject);
                }
                SetupButtonWithTitle(settings.OkButtonTitle, button: okButton, isStacked: isStacked);
            }

            if (settings.CancelButtonTitle != null)
            {
                if (cancelButton == null)
                {
                    cancelButton                = new BFPaperButton();
                    cancelButton.Tag            = 1;
                    cancelButton.TouchUpInside += (sender, args) => PressedAnyButton(sender as NSObject);
                }
                SetupButtonWithTitle(settings.CancelButtonTitle, button: cancelButton, isStacked: isStacked);
            }

            userAction = settings.ButtonAction;

            SetupViewConstraints();

            //// To get dynamic width to work we need to comment this out and uncomment the stuff in setupViewConstraints. But its currently not working..
            SetContainerSize();
            return(this);
        }