public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;

            if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
            {
                EdgesForExtendedLayout = UIRectEdge.None;
            }

            var label = new UILabel
            {
                Text            = "This label has a Height constraint applied to it. \r\nThe toggle switch is bound to the Contraint's Active boolean and the slider to the Constraint's Constant value.",
                BackgroundColor = UIColor.LightGray,
                TextColor       = UIColor.Black,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 0
            };

            var heightToggle      = new UISwitch();
            var labelHeightSlider = new UISlider {
                MinValue = 0, MaxValue = 400
            };

            View.AddSubviews(label, heightToggle, labelHeightSlider);

            View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            var heightLayoutConstraint = label.Height().EqualTo(ViewModel.Constant).WithIdentifier("labelHeight_Constraint_Id");

            var margin = 10;

            View.AddConstraints(
                labelHeightSlider.AtTopOf(View, margin),
                labelHeightSlider.AtLeftOf(View, margin),
                labelHeightSlider.AtRightOf(View, margin),

                heightToggle.Below(labelHeightSlider, margin),
                heightToggle.WithSameLeft(labelHeightSlider),

                label.AtLeftOf(View, margin),
                label.Below(heightToggle, margin),
                label.AtRightOf(View, margin),
                heightLayoutConstraint
                );

            var set = this.CreateBindingSet <UpdateConstraintsView, UpdateConstraintsViewModel>();

            set.Bind(heightLayoutConstraint).For(constraint => constraint.Active).To(vm => vm.Active);
            set.Bind(heightLayoutConstraint).For(constraint => constraint.Constant).To(vm => vm.Constant);
            set.Bind(heightToggle).To(vm => vm.Active);
            set.Bind(labelHeightSlider).To(vm => vm.Constant);
            set.Apply();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;

            if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
            {
                EdgesForExtendedLayout = UIRectEdge.None;
            }

            var label = new UILabel
            {
                Text            = "Update this label's height constraint height constant and active settings",
                BackgroundColor = UIColor.LightGray,
                TextColor       = UIColor.Black,
                LineBreakMode   = UILineBreakMode.WordWrap,
                Lines           = 0
            };
            var toggleHeight   = new UISwitch();
            var heightConstant = new UISlider {
                MinValue = 0, MaxValue = 400
            };

            View.AddSubviews(label, toggleHeight, heightConstant);

            View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

            var heightLayout = label.Height().EqualTo(ViewModel.Constant).WithIdentifier("foo");

            var margin = 10;

            View.AddConstraints(
                heightConstant.AtTopOf(View, margin),
                heightConstant.AtLeftOf(View, margin),
                heightConstant.AtRightOf(View, margin),

                toggleHeight.Below(heightConstant, margin),
                toggleHeight.WithSameLeft(heightConstant),

                label.AtLeftOf(View, margin),
                label.Below(toggleHeight, margin),
                label.AtRightOf(View, margin),
                heightLayout
                );

            var set = this.CreateBindingSet <UpdateConstraintsView, UpdateConstraintsViewModel>();

            set.Bind(heightLayout).For(layout => layout.Active).To(vm => vm.Active);
            set.Bind(heightLayout).For(layout => layout.Constant).To(vm => vm.Constant);
            set.Bind(toggleHeight).To(vm => vm.Active);
            set.Bind(heightConstant).To(vm => vm.Constant);
            set.Apply();
        }
예제 #3
0
파일: ItemView.cs 프로젝트: EnaEd/Tasky
        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);
        }