Beispiel #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.White;

            var tapGesture = new UITapGestureRecognizer(() =>
            {
                _email.ResignFirstResponder();
                _username.ResignFirstResponder();
            });

            View.AddGestureRecognizer(tapGesture);
            View.UserInteractionEnabled = true;

            _timer       = new Timer(OnTimer);
            _mailChecker = new StringHelper();

            _createAcc = new UIButton();
            _createAcc.SetTitle("Create account", UIControlState.Normal);
            _createAcc.SetTitleColor(UIColor.Clear, UIControlState.Disabled);
            Constants.CreateShadow(_createAcc, Constants.R231G72B0, 0.5f, 25, 10, 12);
            _createAcc.Font       = Constants.Bold14;
            _createAcc.TouchDown += CreateAccount;
            View.Add(_createAcc);

            _createAcc.AutoAlignAxisToSuperviewAxis(ALAxis.Horizontal);
            _createAcc.AutoSetDimension(ALDimension.Height, 50);
            _createAcc.AutoPinEdgeToSuperviewEdge(ALEdge.Left, 15);
            _createAcc.AutoPinEdgeToSuperviewEdge(ALEdge.Right, 15);

            _emailUnderline = new UIView();
            _emailUnderline.BackgroundColor = UIColor.FromRGB(240, 240, 240);
            View.AddSubview(_emailUnderline);

            _emailUnderline.AutoPinEdge(ALEdge.Bottom, ALEdge.Top, _createAcc, -50);
            _emailUnderline.AutoSetDimension(ALDimension.Height, 1);
            _emailUnderline.AutoPinEdgeToSuperviewEdge(ALEdge.Left, 35);
            _emailUnderline.AutoPinEdgeToSuperviewEdge(ALEdge.Right, 35);

            _emailLabel           = new UILabel();
            _emailLabel.TextColor = Constants.R255G34B5;
            _emailLabel.Text      = "invalid email";
            _emailLabel.Font      = Constants.Semibold12;
            _emailLabel.Hidden    = true;
            View.AddSubview(_emailLabel);

            _emailLabel.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _emailUnderline);
            _emailLabel.AutoPinEdge(ALEdge.Right, ALEdge.Right, _emailUnderline);

            _email = new UITextField();
            var emailDelegate = new BaseTextFieldDelegate();

            _email.Delegate           = emailDelegate;
            emailDelegate.DoneTapped += () =>
            {
                _email.ResignFirstResponder();
                CreateAccount(null, null);
            };
            _email.Placeholder            = "Email address";
            _email.KeyboardType           = UIKeyboardType.EmailAddress;
            _email.AutocorrectionType     = UITextAutocorrectionType.No;
            _email.AutocapitalizationType = UITextAutocapitalizationType.None;
            _email.TextAlignment          = UITextAlignment.Center;
            _email.ReturnKeyType          = UIReturnKeyType.Go;
            _email.EditingChanged        += CheckMail;

            View.AddSubview(_email);

            _email.AutoPinEdge(ALEdge.Bottom, ALEdge.Top, _emailUnderline, -7);
            _email.AutoPinEdgeToSuperviewEdge(ALEdge.Left, 35);
            _email.AutoPinEdgeToSuperviewEdge(ALEdge.Right, 35);
            _email.AutoSetDimension(ALDimension.Height, 30);

            _usernameUnderline = new UIView();
            _usernameUnderline.BackgroundColor = Constants.R240G240B240;
            View.AddSubview(_usernameUnderline);

            _usernameUnderline.AutoPinEdge(ALEdge.Bottom, ALEdge.Top, _email, -35);
            _usernameUnderline.AutoSetDimension(ALDimension.Height, 1);
            _usernameUnderline.AutoPinEdgeToSuperviewEdge(ALEdge.Left, 35);
            _usernameUnderline.AutoPinEdgeToSuperviewEdge(ALEdge.Right, 35);

            _usernameLabel           = new UILabel();
            _usernameLabel.TextColor = Constants.R255G34B5;
            _usernameLabel.Text      = "username already taken";
            _usernameLabel.Font      = Constants.Semibold12;
            _usernameLabel.Hidden    = true;
            View.AddSubview(_usernameLabel);

            _usernameLabel.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _usernameUnderline);
            _usernameLabel.AutoPinEdge(ALEdge.Right, ALEdge.Right, _usernameUnderline);

            _username = new UITextField();
            var usernameDelegate = new UsernameDelegate();

            _username.Delegate           = usernameDelegate;
            usernameDelegate.DoneTapped += () =>
            {
                _email.BecomeFirstResponder();
            };
            _username.Placeholder            = "Username";
            _username.AutocorrectionType     = UITextAutocorrectionType.No;
            _username.AutocapitalizationType = UITextAutocapitalizationType.None;
            _username.TextAlignment          = UITextAlignment.Center;
            _username.ReturnKeyType          = UIReturnKeyType.Next;
            _username.EditingChanged        += (object sender, EventArgs e) =>
            {
                if (string.IsNullOrEmpty(_username.Text))
                {
                    _presenter.TasksCancel();
                    _timer.Change(Timeout.Infinite, Timeout.Infinite);
                    _usernameUnderline.BackgroundColor = Constants.R240G240B240;
                    _usernameLabel.Hidden = true;
                }
                else
                {
                    _timer.Change(1300, Timeout.Infinite);
                }
            };
            View.AddSubview(_username);

            _username.AutoPinEdge(ALEdge.Bottom, ALEdge.Top, _usernameUnderline, -7);
            _username.AutoPinEdgeToSuperviewEdge(ALEdge.Left, 35);
            _username.AutoPinEdgeToSuperviewEdge(ALEdge.Right, 35);
            _username.AutoSetDimension(ALDimension.Height, 30);

            _loader                  = new UIActivityIndicatorView();
            _loader.Color            = Constants.R231G72B0;
            _loader.HidesWhenStopped = true;

            View.AddSubview(_loader);

            _loader.AutoPinEdge(ALEdge.Left, ALEdge.Right, _username);
            _loader.AutoAlignAxis(ALAxis.Horizontal, _username);

            _registrationLoader                  = new UIActivityIndicatorView();
            _registrationLoader.Color            = UIColor.White;
            _registrationLoader.HidesWhenStopped = true;

            View.AddSubview(_registrationLoader);

            _registrationLoader.AutoAlignAxis(ALAxis.Horizontal, _createAcc);
            _registrationLoader.AutoAlignAxis(ALAxis.Vertical, _createAcc);

            SetBackButton();
        }
        private void LayoutView()
        {
            View.BackgroundColor = UIColor.White;
            _amountLabel         = new UILabel();
            _amountLabel.Text    = "Amount: ";
            _amountLabel.Font    = UIFont.PreferredBody;

            _tipPercentageLabel      = new UILabel();
            _tipPercentageLabel.Text = "Tip %: ";
            _tipPercentageLabel.Font = UIFont.PreferredBody;

            _amount = new UITextField
            {
                KeyboardType = UIKeyboardType.DecimalPad,
                Placeholder  = "Total Amount",
                BorderStyle  = UITextBorderStyle.RoundedRect
            };

            _tipPercentage = new UITextField
            {
                KeyboardType = UIKeyboardType.DecimalPad,
                Placeholder  = "Tip %",
                BorderStyle  = UITextBorderStyle.RoundedRect
            };

            _calculateButton = new UIButton(UIButtonType.RoundedRect);
            _calculateButton.SetTitle("Calculate Tip", UIControlState.Normal);
            _tableView          = new UITableView();
            _clearHistoryButton = new UIButton(UIButtonType.RoundedRect);
            _clearHistoryButton.SetTitle("Clear History", UIControlState.Normal);
            _clearHistoryButton.BackgroundColor = UIColor.FromRGB(243, 105, 105);
            _clearHistoryButton.SetTitleColor(UIColor.White, UIControlState.Normal);

            View.Add(_amount);
            View.Add(_tipPercentage);
            View.Add(_calculateButton);
            View.Add(_tableView);
            View.Add(_clearHistoryButton);

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                _amount.AutoPinEdgeToSuperviewSafeArea(ALEdge.Top, Constants.WideMargin);
                _amount.AutoPinEdgeToSuperviewSafeArea(ALEdge.Left, Constants.DefaultMargin);
            }
            else
            {
                _amount.AutoPinEdgeToSuperviewEdge(ALEdge.Top, Constants.WideMargin);
                _amount.AutoPinEdgeToSuperviewEdge(ALEdge.Left, Constants.DefaultMargin);
            }
            _tipPercentage.AutoPinEdge(ALEdge.Leading, ALEdge.Trailing, _amount, Constants.DefaultMargin);
            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                _tipPercentage.AutoPinEdgeToSuperviewSafeArea(ALEdge.Right, Constants.DefaultMargin);
            }
            else
            {
                _tipPercentage.AutoPinEdgeToSuperviewEdge(ALEdge.Right, Constants.DefaultMargin);
            }
            _tipPercentage.AutoAlignAxis(ALAxis.Baseline, _amount);

            _calculateButton.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _amount, Constants.DefaultMargin);
            _calculateButton.AutoAlignAxisToSuperviewAxis(ALAxis.Vertical);

            _tableView.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _calculateButton, Constants.WideMargin);
            _tableView.AutoPinEdgeToSuperviewEdge(ALEdge.Leading, Constants.DefaultMargin);
            _tableView.AutoPinEdgeToSuperviewEdge(ALEdge.Trailing, Constants.DefaultMargin);
            _tableView.AutoPinEdge(ALEdge.Bottom, ALEdge.Top, _clearHistoryButton);

            _clearHistoryButton.AutoPinEdgesToSuperviewEdgesExcludingEdge(ALEdge.Top);
            _clearHistoryButton.AutoSetDimension(ALDimension.Height, Constants.WideMargin * 2);
            _clearHistoryButton.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, _tableView);
        }
Beispiel #3
0
        void LayoutView()
        {
            // https://stackoverflow.com/questions/19036228/uiscrollview-scrollable-content-size-ambiguity/27227174#27227174
            container = new UIScrollView();
            var containerView = new UIView();

            container.Frame           = View.Bounds;
            container.BackgroundColor = UIColor.Clear;
            container.ContentSize     = View.Bounds.Size;


            UIImage logoSmall = Constants.MaxResizeImage(UIImage.FromBundle(@"small_logo"), 250, 20);

            logoImageView             = new UIImageView(logoSmall);
            logoImageView.ContentMode = UIViewContentMode.ScaleAspectFit;



            var textFieldBackgroundColor = Constants.UIColorFromRGB(0x4b4f63);

            usernameTextField = new UITextField {
                AutocapitalizationType = UITextAutocapitalizationType.None, BackgroundColor = textFieldBackgroundColor, TextColor = UIColor.White, KeyboardType = UIKeyboardType.Default, BorderStyle = UITextBorderStyle.RoundedRect
            };
            //usernameTextField.Frame = new CGRect(0, 0, View.Bounds.Width - 20, 40);
            usernameTextField.AttributedPlaceholder = new NSAttributedString("Username", foregroundColor: UIColor.LightTextColor);
            usernameTextField.ShouldReturn          = delegate {
                passwordTextField.BecomeFirstResponder();
                return(true);
            };


            passwordTextField = new UITextField {
                SecureTextEntry = true, BackgroundColor = textFieldBackgroundColor, TextColor = UIColor.White, BorderStyle = UITextBorderStyle.RoundedRect
            };
            passwordTextField.AttributedPlaceholder = new NSAttributedString("Password", foregroundColor: UIColor.LightTextColor, font: UIFont.SystemFontOfSize(17f));
            passwordTextField.ShouldReturn          = delegate {
                passwordTextField.ResignFirstResponder();
                return(true);
            };

            var loginButtonBackgroundColor = Constants.UIColorFromRGB(0xff3333);

            loginButton = new UIButton(UIButtonType.RoundedRect);
            loginButton.BackgroundColor = loginButtonBackgroundColor;
            loginButton.SetTitle("LOG IN", UIControlState.Normal);
            loginButton.SetTitleColor(UIColor.White, UIControlState.Normal);
            loginButton.Font = UIFont.BoldSystemFontOfSize(24);
            loginButton.Layer.CornerRadius = 10f;
            loginButton.TouchUpInside     += LoginButton_TouchUpInside;


            container.AddSubview(containerView);
            containerView.AddSubviews(new UIView[] { logoImageView, usernameTextField, passwordTextField, loginButton });
            this.View.AddSubviews(new UIView[] { container });

            #region Setup Autolayouts

            container.AutoPinEdgeToSuperviewEdge(ALEdge.Top, 0);
            container.AutoPinEdgeToSuperviewEdge(ALEdge.Right, 0);
            container.AutoPinEdgeToSuperviewEdge(ALEdge.Left, 0);
            container.AutoPinEdgeToSuperviewEdge(ALEdge.Bottom, 0);

            containerView.AutoPinEdgeToSuperviewEdge(ALEdge.Top, 0);
            containerView.AutoPinEdgeToSuperviewEdge(ALEdge.Right, 0);
            containerView.AutoPinEdgeToSuperviewEdge(ALEdge.Left, 0);
            containerView.AutoPinEdgeToSuperviewEdge(ALEdge.Bottom, 0);
            containerView.AutoAlignAxisToSuperviewAxis(ALAxis.Horizontal);
            containerView.AutoAlignAxisToSuperviewAxis(ALAxis.Vertical);



            logoImageView.AutoPinEdgeToSuperviewEdge(ALEdge.Top, 120);

            logoImageView.AutoPinEdgeToSuperviewEdge(ALEdge.Left, (UIScreen.MainScreen.Bounds.Width - logoImageView.Bounds.Width) / 2);
            logoImageView.AutoPinEdgeToSuperviewEdge(ALEdge.Right, (UIScreen.MainScreen.Bounds.Width - logoImageView.Bounds.Width) / 2);
            logoImageView.AutoSetDimension(ALDimension.Height, 31);



            usernameTextField.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, logoImageView, 30);
            usernameTextField.AutoPinEdgeToSuperviewEdge(ALEdge.Left, Constants.WideMargin);
            usernameTextField.AutoPinEdgeToSuperviewEdge(ALEdge.Right, Constants.WideMargin);
            usernameTextField.AutoSetDimension(ALDimension.Height, 40);

            passwordTextField.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, usernameTextField, 12);
            passwordTextField.AutoPinEdgeToSuperviewEdge(ALEdge.Left, Constants.WideMargin);
            passwordTextField.AutoPinEdgeToSuperviewEdge(ALEdge.Right, Constants.WideMargin);
            passwordTextField.AutoSetDimension(ALDimension.Height, 40);

            //loginButton.Layer.BorderWidth = 1;
            //loginButton.Layer.BorderColor = UIColor.Blue.CGColor;
            loginButton.AutoPinEdge(ALEdge.Top, ALEdge.Bottom, passwordTextField, 20);
            loginButton.AutoPinEdgeToSuperviewEdge(ALEdge.Left, Constants.WideMargin);
            loginButton.AutoPinEdgeToSuperviewEdge(ALEdge.Right, Constants.WideMargin);
            loginButton.AutoSetDimension(ALDimension.Height, 50);



            #endregion
        }