コード例 #1
0
        public CustomPopUpView(string message, string buttonText, CGSize size)
        {
            UIImageView img = null;

            this.Layer.CornerRadius  = _cornerRadius;
            this.Layer.MasksToBounds = true;
            _effectView.Alpha        = 0;

            this.BackgroundColor = UIColor.White;

            img = new UIImageView(UIImage.FromBundle("UploadDocumentIcon.png"));

            img.Frame = new CoreGraphics.CGRect(10, 40, img.Image.CGImage.Width / 2, img.Image.CGImage.Height / 2);
            var messageBody  = string.IsNullOrEmpty(message + "\n") ? "Error" : message + "\n";
            var messageLabel = new UILabel()
            {
                BackgroundColor  = UIColor.Clear,
                TextColor        = UIColor.Black,
                Text             = messageBody,
                TextAlignment    = UITextAlignment.Left,
                AutoresizingMask = UIViewAutoresizing.All,
                LineBreakMode    = UILineBreakMode.WordWrap,
                Lines            = 0
            };

            var messageLabelSize = messageLabel.Text.StringSize(messageLabel.Font, new SizeF((float)size.Width, 500));

            var messageLabelHeight = messageLabelSize.Height + 20;

            messageLabel.Frame = new CGRect((img.Image.CGImage.Width / 2) + 20, 30, 220, messageLabelHeight);

            var additionalFrameHeight = (messageLabelHeight - size.Height) < 0 ? 90 + (messageLabelHeight - size.Height) : (messageLabelHeight - size.Height) + 90;

            nfloat lx = (UIScreen.MainScreen.Bounds.Width - size.Width) / 2;
            nfloat ly = (UIScreen.MainScreen.Bounds.Height - (size.Height + additionalFrameHeight)) / 2;

            this.Frame = new CGRect(new CGPoint(lx, ly), new CGSize(size.Width, size.Height + additionalFrameHeight));

            var stack = new UIStackView()
            {
                Alignment = UIStackViewAlignment.Center
            };

            stack.Frame = new CGRect(0, 0, this.Frame.Width, this.Frame.Height);

            _actionBtn.SetTitle(buttonText, UIControlState.Normal);
            _actionBtn.Frame           = new CGRect(0, this.Frame.Height - _btnHeight, this.Frame.Width, _btnHeight);
            _actionBtn.BackgroundColor = UIColor.FromRGB(4, 103, 161);
            _actionBtn.SetTitleColor(UIColor.White, UIControlState.Normal);
            _actionBtn.TouchUpInside += delegate
            {
                YesButtonClicked?.Invoke();
                Close();
            };

            stack.AddSubview(messageLabel);
            stack.AddSubview(img);
            stack.AddSubview(_actionBtn);
            this.AddSubview(stack);
        }
コード例 #2
0
            public CustomPopUpView(string message, string yesButtonText, string noButtonText, CGSize size)
            {
                nfloat lx = (UIScreen.MainScreen.Bounds.Width - size.Width) / 2;
                nfloat ly = (UIScreen.MainScreen.Bounds.Height - size.Height) / 2;

                this.Frame = new CGRect(new CGPoint(lx, ly), size);
                this.Layer.CornerRadius  = CornerRadius;
                this.Layer.MasksToBounds = true;
                _effectView.Alpha        = 0;

                this.BackgroundColor = UIColor.White;

                var messageBody = string.IsNullOrEmpty(message + "\n") ? "Error" : message + "\n";
                var label       = new UILabel
                {
                    BackgroundColor  = UIColor.Clear,
                    TextColor        = UIColor.Black,
                    Text             = messageBody,
                    TextAlignment    = UITextAlignment.Left,
                    AutoresizingMask = UIViewAutoresizing.All,
                    LineBreakMode    = UILineBreakMode.WordWrap,
                    Lines            = 0
                };
                var labelSize   = label.Text.StringSize(label.Font, new SizeF((float)this.Frame.Width, 500));
                var labelHeight = labelSize.Height + 25;

                label.Frame = new CGRect(this.Frame.Width, labelHeight > 25 ? 30 : 50, 200, labelHeight);

                var stack = new UIStackView
                {
                    Alignment = UIStackViewAlignment.Center,
                    Frame     = new CGRect(0, 0, this.Frame.Width, this.Frame.Height)
                };

                _btnClose.SetTitle(noButtonText, UIControlState.Normal);
                _btnClose.Frame           = new CGRect(this.Frame.Width / 2, this.Frame.Height - _btnHeight, this.Frame.Width / 2, _btnHeight);
                _btnClose.BackgroundColor = UIColor.FromRGB(245, 245, 245);
                _btnClose.SetTitleColor(UIColor.Black, UIControlState.Normal);
                _btnClose.TouchUpInside += delegate
                {
                    NoButtonClicked?.Invoke();
                    Close();
                };

                _actionBtn.SetTitle(yesButtonText, UIControlState.Normal);
                _actionBtn.Frame           = new CGRect(0, this.Frame.Height - _btnHeight, this.Frame.Width / 2, _btnHeight);
                _actionBtn.BackgroundColor = UIColor.FromRGB(245, 16, 16);
                _actionBtn.SetTitleColor(UIColor.White, UIControlState.Normal);
                _actionBtn.TouchUpInside += delegate
                {
                    YesButtonClicked?.Invoke();
                    Close();
                };

                stack.AddSubview(label);
                stack.AddSubview(_btnClose);
                stack.AddSubview(_actionBtn);
                this.AddSubview(stack);
            }
コード例 #3
0
        public CustomMessageBox(string text, MessageBoxButton buttons)
        {
            InitializeComponent();

            Text                     = text;
            MessageText.Text         = text;
            MessageText.TextWrapping = TextWrapping.Wrap;
            MessageText.Padding      = new Thickness(10);

            switch (buttons)
            {
            case MessageBoxButton.OK:
                RoundedButton button = new RoundedButton("OK", new SolidColorBrush(ColorScheme.GlobalBlue),
                                                         new SolidColorBrush(ColorScheme.MenuLight));
                button.Clicked += (s, ea) =>
                {
                    OKButtonClicked?.Invoke(this, EventArgs.Empty);
                };

                DockPanel.SetDock(button, Dock.Right);
                ButtonsContainer.Children.Add(button);
                break;

            case MessageBoxButton.YesNo:
                RoundedButton yesbutton = new RoundedButton("Tak", new SolidColorBrush(ColorScheme.GlobalBlue),
                                                            new SolidColorBrush(ColorScheme.MenuLight));
                yesbutton.Clicked += (s, ea) =>
                {
                    YesButtonClicked?.Invoke(this, EventArgs.Empty);
                };

                DockPanel.SetDock(yesbutton, Dock.Right);
                ButtonsContainer.Children.Add(yesbutton);

                RoundedButton nobutton = new RoundedButton("Nie", new SolidColorBrush(ColorScheme.GlobalBlue),
                                                           new SolidColorBrush(ColorScheme.MenuLight));
                nobutton.Clicked += (s, ea) =>
                {
                    NoButtonClicked?.Invoke(this, EventArgs.Empty);
                };

                DockPanel.SetDock(nobutton, Dock.Right);
                ButtonsContainer.Children.Add(nobutton);
                break;
            }
        }
コード例 #4
0
            public CustomPopUpView(string message, string buttonText, CGSize size, bool isWarning = false)
            {
                nfloat      lx  = (UIScreen.MainScreen.Bounds.Width - size.Width) / 2;
                nfloat      ly  = (UIScreen.MainScreen.Bounds.Height - size.Height) / 2;
                UIImageView img = null;

                this.Frame = new CGRect(new CGPoint(lx, ly), size);
                this.Layer.MasksToBounds = true;
                _effectView.Alpha        = 0;

                this.BackgroundColor = UIColor.White;

                if (isWarning)
                {
                    img = new UIImageView(UIImage.FromBundle("InfoIcon.png"));
                }
                else
                {
                    img = new UIImageView(UIImage.FromBundle("OkIcon.png"));
                }

                img.Frame = new CoreGraphics.CGRect(10, 40, img.Image.CGImage.Width / 2, img.Image.CGImage.Height / 2);
                string messageBody;

                if (message.ToCharArray().Length < 28)
                {
                    messageBody = string.IsNullOrEmpty(message) ? "Error" : message;
                }
                else
                {
                    messageBody = string.IsNullOrEmpty(message + "\n") ? "Error" : message + "\n";
                }
                var label = new UILabel()
                {
                    BackgroundColor  = UIColor.Clear,
                    TextColor        = UIColor.Black,
                    Text             = messageBody,
                    TextAlignment    = UITextAlignment.Left,
                    AutoresizingMask = UIViewAutoresizing.All,
                    LineBreakMode    = UILineBreakMode.WordWrap,
                    Lines            = 0
                };
                var labelSize = label.Text.StringSize(label.Font, new SizeF((float)this.Frame.Width, 500));

                label.Frame = new CGRect((img.Image.CGImage.Width / 2) + 20, labelSize.Height > 40 ? 35 : 50, 200, labelSize.Height);

                var stack = new UIStackView()
                {
                    Alignment = UIStackViewAlignment.Center
                };

                stack.Frame = new CGRect(0, 0, this.Frame.Width, this.Frame.Height);

                _actionBtn.SetTitle(buttonText, UIControlState.Normal);
                _actionBtn.Frame           = new CGRect(0, this.Frame.Height - _btnHeight, this.Frame.Width, _btnHeight);
                _actionBtn.BackgroundColor = UIColor.FromRGB(4, 103, 161);
                _actionBtn.SetTitleColor(UIColor.White, UIControlState.Normal);
                _actionBtn.TouchUpInside += delegate
                {
                    YesButtonClicked?.Invoke();
                    Close();
                };

                stack.AddSubview(label);
                stack.AddSubview(img);
                stack.AddSubview(_actionBtn);
                this.AddSubview(stack);
            }