コード例 #1
0
ファイル: CRSAlertView.cs プロジェクト: Runesmacher/Totemapp
        public static CRSAlertView Error(string title, string message, UIImage image = null, string buttonTitle = "Ok")
        {
            var action = new CRSAlertAction {
                Text        = buttonTitle,
                Highlighted = true,
                TintColor   = Tint
            };

            return(new CRSAlertView {
                Title = title,
                Message = message,
                Image = image != null ? image : UIImage.FromBundle(""),
                Actions = new CRSAlertAction[] { action },
            });
        }
コード例 #2
0
ファイル: CRSAlertView.cs プロジェクト: FrederickEskens/Totem
 public static CRSAlertView Error(string title, string message, UIImage image = null, string buttonTitle = "Ok")
 {
     var action = new CRSAlertAction {
         Text = buttonTitle,
         Highlighted = true,
         TintColor = Tint
     };
     return new CRSAlertView {
         Title = title,
         Message = message,
         Image = image != null ? image : UIImage.FromBundle(""),
         Actions = new CRSAlertAction[] { action },
     };
 }
コード例 #3
0
ファイル: CRSAlertView.cs プロジェクト: Runesmacher/Totemapp
        private void MakeUI()
        {
            CreateAlertWindow();

            // Needs these parameters
            if (CRSAlertView.AlertWindow == null || Title == null || Actions == null || Actions.Length == 0)
            {
                throw new ModelNotImplementedException();
            }

            // Build Main View
            Alpha           = 0f;
            BackgroundColor = UIColor.Black.ColorWithAlpha(0.5f);
            Frame           = CRSAlertView.AlertWindow.Bounds;

            // Build Container
            nfloat imageWidth   = 40f;
            nfloat buttonWidth  = (CRSAlertView.AlertWindow.Frame.Width - 2 * pad) / Actions.Length;
            nfloat buttonHeight = 60f;

            _alertContainer = new UIView {
                Frame           = new CGRect(pad, 0, CRSAlertView.AlertWindow.Frame.Width - 2 * pad, pad),
                BackgroundColor = Background,
                Alpha           = 0f
            };
            _alertContainer.Layer.CornerRadius  = 10.0f;
            _alertContainer.Layer.MasksToBounds = true;

            _image = new UIImageView {
                Frame           = new CGRect(_alertContainer.Frame.Width / 2 - imageWidth / 2 - 20, pad, Image != null ? imageWidth : 0, Image != null ? imageWidth : 0),
                BackgroundColor = UIColor.Clear,
                TintColor       = TitleTextColor,
                Image           = Image ?? new UIImage(),
                ContentMode     = UIViewContentMode.ScaleAspectFit
            };

            _title = new UILabel {
                Frame     = new CGRect(_alertContainer.Frame.Width / 2 - imageWidth / 2 + 20, pad, Image != null ? imageWidth : 0, Image != null ? imageWidth : 0),
                Text      = Title,
                TextColor = TitleTextColor,
                Font      = TitleFont,
                Lines     = 1,
                AdjustsFontSizeToFitWidth = true,
                MinimumScaleFactor        = 0.5f,
                TextAlignment             = UITextAlignment.Center
            };

            _message = new UILabel {
                Frame         = new CGRect(pad / 2, _title.Frame.Bottom + 10, _alertContainer.Frame.Width - pad, 20.0f),
                Text          = Message,
                TextColor     = MessageTextColor,
                Font          = MessageFont,
                Lines         = 0,
                TextAlignment = UITextAlignment.Center
            };
            _message.SizeToFit();
            _message.Center = new CGPoint(_title.Center.X - 20, _message.Center.Y);

            if (Input != null)
            {
                _inputImage = new UIImageView {
                    Frame     = new CGRect(pad / 2, _message.Frame.Bottom + pad / 2, Input.Image != null ? 20 : 0, Input.Image != null ? 20 : 0),
                    Image     = Input.Image ?? new UIImage(),
                    TintColor = Input.TintColor != null ? Input.TintColor : Tint
                };

                var startX = Input.Image != null ? pad / 2 + 30 : pad / 2;
                _inputTextField = new UITextField {
                    Frame              = new CGRect(startX, _message.Frame.Bottom + pad / 2, _alertContainer.Frame.Width - _inputImage.Frame.Right - 20, 30),
                    BackgroundColor    = UIColor.White,
                    Placeholder        = Input.Placeholder != null ? Input.Placeholder : "",
                    Text               = Input.Text != null ? Input.Text : "",
                    TextColor          = InputTextColor,
                    Font               = InputFont,
                    BorderStyle        = UITextBorderStyle.None,
                    Alpha              = 0f,
                    Delegate           = new InputSource(),
                    ReturnKeyType      = UIReturnKeyType.Done,
                    KeyboardAppearance = UIKeyboardAppearance.Dark
                };
                _inputTextField.Layer.SublayerTransform = CATransform3D.MakeTranslation(5.0f, 0.0f, 0.0f);

                _inputLabel = new UILabel {
                    Frame     = new CGRect(startX, _message.Frame.Bottom + pad / 2, _alertContainer.Frame.Width - _inputImage.Frame.Right + 20, 30),
                    TextColor = Input.TintColor != null ? Input.TintColor : Tint,
                    Text      = Input.Placeholder != null ? Input.Placeholder : "",
                    Alpha     = 0,
                    Font      = InputFont
                };

                _inputButton = new UIButton {
                    BackgroundColor = UIColor.Clear
                };
                _inputButton.TouchUpInside += (sender, e) => {
                    ShowInputTextField();
                };

                _alertContainer.AddSubviews(new UIView[] { _inputImage, _inputLabel, _inputButton, _inputTextField });

                if (Input.OpenAutomatically)
                {
                    _inputButton.Hidden   = true;
                    _inputTextField.Alpha = 1f;
                    _inputImage.Center    = new CGPoint(_inputImage.Center.X, _inputTextField.Center.Y);
                }
                else
                {
                    _inputLabel.SizeToFit();
                    _inputLabel.Alpha = 1f;
                    nfloat width = _inputImage.Frame.Width + 10 + _inputLabel.Frame.Width;
                    _inputImage.Frame   = new CGRect(_alertContainer.Frame.Width / 2 - width / 2, _inputImage.Frame.Top, _inputImage.Frame.Width, _inputImage.Frame.Height);
                    _inputLabel.Frame   = new CGRect(_inputImage.Frame.Right + 10, _inputLabel.Frame.Top, _inputLabel.Frame.Width, _inputLabel.Frame.Height);
                    _inputImage.Center  = new CGPoint(_inputImage.Center.X, _inputLabel.Center.Y);
                    _inputButton.Frame  = new CGRect(_inputImage.Frame.Left, _inputLabel.Frame.Top, width, 44);
                    _inputButton.Center = new CGPoint(_inputButton.Center.X, _inputLabel.Center.Y);
                }
            }

            _bottomSeparator = new UIView {
                Frame           = new CGRect(0, Input == null ? _message.Frame.Bottom + pad : _inputLabel.Frame.Bottom + pad, _alertContainer.Frame.Width, 1),
                BackgroundColor = SeparatorColor
            };
            _alertContainer.AddSubviews(new UIView[] { _image, _title, _message, _bottomSeparator });

            for (int i = 0; i < Actions.Length; i++)
            {
                CRSAlertAction action = Actions [i];
                var            btn    = new UIButton {
                    Frame           = new CGRect(buttonWidth * i, _bottomSeparator.Frame.Bottom, buttonWidth, buttonHeight),
                    BackgroundColor = ButtonBackground,
                    Font            = action.Highlighted ? AlertButtonHighlightedFont : AlertButtonNormalFont
                };
                btn.ContentMode = UIViewContentMode.ScaleAspectFit;
                btn.SetTitle(string.IsNullOrEmpty(action.Text) ? "" : action.Text, UIControlState.Normal);
                btn.Tag        = i;
                btn.TouchDown += (sender, e) => {
                    btn.BackgroundColor = ButtonHighlighted;
                };
                btn.TouchUpOutside += (sender, e) => {
                    btn.BackgroundColor = ButtonBackground;
                };
                btn.TouchUpInside += (sender, e) => {
                    DidSelectAction((int)btn.Tag);
                };
                btn.SetTitleColor(action.Highlighted ? (action.TintColor ?? Tint) : TitleTextColor, UIControlState.Normal);
                _alertContainer.Add(btn);
                if (i < Actions.Length - 1)
                {
                    var s = new UIView {
                        Frame           = new CGRect(btn.Frame.Right - 1, btn.Frame.Top, 1, buttonHeight),
                        BackgroundColor = SeparatorColor
                    };
                    _alertContainer.Add(s);
                }
            }
            nfloat alertEnd = (_alertContainer.Subviews[_alertContainer.Subviews.Length - 1] as UIView).Frame.Bottom;

            _alertContainer.Frame  = new CGRect(_alertContainer.Frame.Left, _alertContainer.Frame.Top, _alertContainer.Frame.Width, alertEnd);
            _alertContainer.Center = new CGPoint(CRSAlertView.AlertWindow.Frame.Width / 2, CRSAlertView.AlertWindow.Frame.Height / 2);
            Add(_alertContainer);
        }