Beispiel #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.BackgroundColor = UIColor.FromRGB(204, 242, 255);

            var    border = new CALayer();
            nfloat width  = 2;

            border.BorderColor = UIColor.Black.CGColor;
            border.BorderWidth = width;

            ViewModel.Show();

            _contentConteiner = new UIView();
            _scrollView       = new UIScrollView();
            _scrollView.AddSubview(_contentConteiner);
            Add(_scrollView);

            var _BackBarButton = new UIBarButtonItem();

            _BackBarButton.Title             = "Back";
            NavigationItem.LeftBarButtonItem = _BackBarButton;

            _peopleConroller = new ABPeoplePickerNavigationController();
            _peopleConroller.SelectPerson2 += SelectPeople;
            _peopleConroller.Cancelled     += delegate
            {
                this.DismissModalViewController(true);
            };

            _labelTaskName = new UILabel();
            _contentConteiner.AddSubview(_labelTaskName);


            _labelError           = new UILabel();
            _labelError.Font      = _labelError.Font.WithSize(10);
            _labelError.TextColor = UIColor.Red;
            _contentConteiner.AddSubview(_labelError);

            _textEdit              = new UITextField();
            _textEdit.Placeholder  = "todo...";
            _textEdit.BorderStyle  = UITextBorderStyle.RoundedRect;
            _textEdit.ShouldReturn = (textField) =>
            {
                textField.ResignFirstResponder();
                return(true);
            };
            _contentConteiner.AddSubview(_textEdit);

            _textContactName              = new UITextField();
            _textContactName.Placeholder  = "add contact...";
            _textContactName.BorderStyle  = UITextBorderStyle.RoundedRect;
            _textContactName.ShouldReturn = (textField) =>
            {
                textField.ResignFirstResponder();
                return(true);
            };
            _contentConteiner.AddSubview(_textContactName);

            _textContactPhone               = new UITextField();
            _textContactPhone.Placeholder   = "add Phone...";
            _textContactPhone.KeyboardType  = UIKeyboardType.NamePhonePad;
            _textContactPhone.ReturnKeyType = UIReturnKeyType.Done;
            _textContactPhone.BorderStyle   = UITextBorderStyle.RoundedRect;
            _textContactPhone.ShouldReturn  = (textField) =>
            {
                textField.ResignFirstResponder();
                return(true);
            };
            _contentConteiner.AddSubview(_textContactPhone);

            _buttonSelectContact = new UIButton();
            _buttonSelectContact.BackgroundColor = UIColor.Blue;
            _buttonSelectContact.SetTitle("Add", UIControlState.Normal);
            _buttonSelectContact.Layer.CornerRadius = 5;
            _buttonSelectContact.Layer.BorderWidth  = 1;
            _buttonSelectContact.TouchUpInside     += delegate { PresentModalViewController(_peopleConroller, true); };
            _contentConteiner.AddSubview(_buttonSelectContact);

            _buttonCall = new UIButton();
            _buttonCall.BackgroundColor = UIColor.Blue;
            _buttonCall.SetTitle("Call", UIControlState.Normal);
            _buttonCall.Layer.CornerRadius = 5;
            _buttonCall.Layer.BorderWidth  = 1;
            _contentConteiner.AddSubview(_buttonCall);

            _swith    = new UISwitch();
            _swith.On = true;
            _contentConteiner.AddSubview(_swith);

            _buttonSave = new UIButton(UIButtonType.Custom);
            _buttonSave.BackgroundColor    = UIColor.Blue;
            _buttonSave.Layer.CornerRadius = 5;
            _buttonSave.Layer.BorderWidth  = 1;
            _buttonSave.SetTitle("Save", UIControlState.Normal);
            _contentConteiner.AddSubview(_buttonSave);

            _buttonDelete = new UIButton(UIButtonType.Custom);
            _buttonDelete.Layer.CornerRadius = 5;
            _buttonDelete.Layer.BorderWidth  = 1;
            _buttonDelete.BackgroundColor    = UIColor.Blue;
            _buttonDelete.SetTitle("Delete", UIControlState.Normal);
            _buttonDelete.TitleColor(UIControlState.Selected);
            _contentConteiner.AddSubview(_buttonDelete);

            var set = this.CreateBindingSet <ItemView, ItemViewModel>();

            set.Bind(_BackBarButton).To(vm => vm.BackToCommand);
            set.Bind(_labelTaskName).To(vm => vm.TaskName);
            set.Bind(_textEdit).To(vm => vm.TaskContent);
            set.Bind(_swith).To(vm => vm.TaskDone);
            set.Bind(_buttonSave).To(vm => vm.SaveItem);
            set.Bind(_buttonDelete).To(vm => vm.DeleteItem);
            set.Bind(_textContactName).To(vm => vm.ContactName);
            set.Bind(_textContactPhone).To(vm => vm.ContactPhone);
            set.Bind(_buttonCall).To(vm => vm.PhoneCallCommand);
            set.Bind(_labelError).To(vm => vm.Error);
            set.Apply();

            //conastraint
            _scrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
            _scrollView.AddConstraints(_contentConteiner.FullWidthOf(_scrollView));
            _scrollView.AddConstraints(_contentConteiner.FullHeightOf(_scrollView));

            View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            View.AddConstraints(_scrollView.FullWidthOf(View));
            View.AddConstraints(_scrollView.FullHeightOf(View));
            View.AddConstraints(
                _contentConteiner.WithSameWidth(View),
                _contentConteiner.WithSameHeight(View).SetPriority(UILayoutPriority.DefaultLow)
                );

            _contentConteiner.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            _contentConteiner.AddConstraints(

                _labelError.AtTopOf(_contentConteiner),
                _labelError.WithSameWidth(_contentConteiner),
                _labelError.WithSameCenterX(_contentConteiner),
                _labelError.Height().EqualTo(20),

                _labelTaskName.WithSameCenterX(_contentConteiner),
                _labelTaskName.Below(_labelError, 25),
                _labelTaskName.WithSameWidth(_contentConteiner).Minus(130),
                _labelTaskName.Height().LessThanOrEqualTo(60),

                _textEdit.WithSameCenterX(_contentConteiner),
                _textEdit.Below(_labelTaskName, 20),
                _textEdit.WithSameWidth(_contentConteiner).Minus(25),
                _textEdit.Height().LessThanOrEqualTo(60),

                _textContactName.AtLeftOf(_contentConteiner, 25),
                _textContactName.Below(_textEdit, 20),
                _textContactName.WithSameWidth(_contentConteiner).Minus(130),
                _textContactName.Height().EqualTo(40),

                _textContactPhone.AtLeftOf(_contentConteiner, 25),
                _textContactPhone.Below(_textContactName, 20),
                _textContactPhone.WithSameWidth(_contentConteiner).Minus(130),
                _textContactPhone.Height().EqualTo(40),

                _buttonSelectContact.ToRightOf(_textContactName, 20),
                _buttonSelectContact.WithSameCenterY(_textContactName),
                _buttonSelectContact.Width().EqualTo(80),

                _swith.AtLeftOf(_contentConteiner, 25),
                _swith.Below(_textContactPhone, 20),

                _buttonCall.WithSameCenterY(_textContactPhone),
                _buttonCall.ToRightOf(_textContactPhone, 20),
                _buttonCall.Width().EqualTo(80),

                _buttonSave.AtLeftOf(_contentConteiner, 25),
                _buttonSave.Below(_swith, 40),
                _buttonSave.Width().EqualTo(80),
                _buttonSave.Height().LessThanOrEqualTo(35),

                _buttonDelete.WithSameCenterX(_buttonCall),
                _buttonDelete.Below(_swith, 40),
                _buttonDelete.Width().EqualTo(80),
                _buttonDelete.Height().LessThanOrEqualTo(35)

                );
            // very important to make scrolling work
            var bottomViewConstraint = _contentConteiner.Subviews.Last()
                                       .AtBottomOf(_contentConteiner).Minus(20);

            _contentConteiner.AddConstraints(bottomViewConstraint);
        }
Beispiel #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.FromRGB(77, 210, 255);

            //save user
            _filePath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "ToDoUser.txt");
            File.WriteAllText(_filePath, $"{SignViewModel.UserCurrent.UserLogin}`" +
                              $"{SignViewModel.UserCurrent.UserPassword}");

            _contentConteiner = new UIView();
            _scrollView       = new UIScrollView();
            _scrollView.AddSubview(_contentConteiner);
            Add(_scrollView);

            _titleView = new UIView();
            _titleView.BackgroundColor    = UIColor.FromRGB(245, 245, 239);
            _titleView.Layer.CornerRadius = 10;
            _contentConteiner.AddSubview(_titleView);

            _userImage = new UIImageView();
            _userImage.BackgroundColor = UIColor.LightGray;
            _contentConteiner.AddSubview(_userImage);

            _imageButton = new UIButton();
            _imageButton.BackgroundColor = UIColor.Clear;
            _imageButton.TouchUpInside  += ChoosePicture;
            _contentConteiner.AddSubview(_imageButton);

            _userLogin = new UILabel();
            _contentConteiner.AddSubview(_userLogin);

            _home = new UIButton();
            _home.SetTitle("Task List", UIControlState.Normal);
            _home.SetTitleColor(UIColor.Black, UIControlState.Normal);
            _home.TitleLabel.ShadowOffset        = new CGSize(width: 0, height: 0.1);
            _home.TitleLabel.Layer.ShadowOpacity = 1;
            _home.TitleLabel.Layer.ShadowRadius  = 8;
            _home.TitleLabel.Layer.MasksToBounds = false;
            _home.SetImage(UIImage.FromFile("Image/todoIOS.png"), UIControlState.Normal);
            _home.TouchUpInside += delegate { File.Delete(_filePath);
                                              ViewModel.GoHome();
                                              Mvx.Resolve <IMvxSideMenu>().Close(); };
            _contentConteiner.AddSubview(_home);

            _logOff = new UIButton();
            _logOff.SetTitle("LogOff", UIControlState.Normal);
            _logOff.SetTitleColor(UIColor.Black, UIControlState.Normal);
            _logOff.TitleLabel.ShadowOffset        = new CGSize(width: 0, height: 0.1);
            _logOff.TitleLabel.Layer.ShadowOpacity = 1;
            _logOff.TitleLabel.Layer.ShadowRadius  = 8;
            _logOff.TitleLabel.Layer.MasksToBounds = false;
            _logOff.SetImage(UIImage.FromFile("Image/logoffIOS.png"), UIControlState.Normal);
            _logOff.TouchUpInside += delegate { File.Delete(_filePath);
                                                ViewModel.DoLogOff();
                                                Mvx.Resolve <IMvxSideMenu>().Close(); };
            _contentConteiner.AddSubview(_logOff);

            var set = this.CreateBindingSet <LeftPanelView, LeftPanelViewModel>();

            set.Bind(_userImage).For(v => v.Image).To(vm => vm.UserImage).WithConversion("ByteToUIImage");
            set.Bind(_userLogin).To(vm => vm.UserLogin);
            set.Apply();

            //conastraint
            _scrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
            _scrollView.AddConstraints(_contentConteiner.FullWidthOf(_scrollView));
            _scrollView.AddConstraints(_contentConteiner.FullHeightOf(_scrollView));

            View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            View.AddConstraints(_scrollView.FullWidthOf(View));
            View.AddConstraints(_scrollView.FullHeightOf(View));
            View.AddConstraints(
                _contentConteiner.WithSameWidth(View),
                _contentConteiner.WithSameHeight(View).SetPriority(UILayoutPriority.DefaultLow)
                );

            _contentConteiner.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            _contentConteiner.AddConstraints(
                _titleView.WithSameCenterX(_contentConteiner),
                _titleView.AtTopOf(_contentConteiner).Plus(20),
                _titleView.Height().EqualTo(250),
                _titleView.WithSameWidth(_contentConteiner).Minus(10),

                _userImage.WithSameCenterX(_titleView),
                _userImage.WithSameCenterY(_titleView),
                _userImage.Height().EqualTo(120),
                _userImage.Width().EqualTo(120),

                _imageButton.Height().EqualTo(120),
                _imageButton.Width().EqualTo(120),
                _imageButton.WithSameCenterX(_userImage),
                _imageButton.WithSameCenterY(_userImage),

                _userLogin.Below(_userImage, 10),
                _userLogin.WithSameCenterX(_userImage),

                _home.Below(_userLogin, 50),
                _home.AtLeftOf(_contentConteiner, 5),

                _logOff.Below(_home, 5),
                _logOff.AtLeftOf(_contentConteiner, 5)
                );

            // very important to make scrolling work
            var bottomViewConstraint = _contentConteiner.Subviews.Last()
                                       .AtBottomOf(_contentConteiner).Minus(20);

            _contentConteiner.AddConstraints(bottomViewConstraint);
        }