Exemplo n.º 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _stackView = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis         = UILayoutConstraintAxis.Vertical,
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.EqualSpacing,
                Spacing      = 1
            };

            var scroll = new UIScrollView();

            Add(scroll);

            scroll.AddSubview(_stackView);
            scroll.FullSizeOf(View);
            scroll.EnableAutoLayout();

            _stackView.FullSizeOf(scroll);
            _stackView.WidthAnchor
            .ConstraintEqualTo(scroll.WidthAnchor)
            .Active = true;

            for (var i = 0; i < 25; i++)
            {
                _stackView.AddArrangedSubview(
                    GetButton($"Category {i + 1}", i));

                _stackView.AddArrangedSubview(
                    GetContent($"Child of category {i + 1}", i + 100));
            }
        }
Exemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _stackView = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis         = UILayoutConstraintAxis.Vertical,
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.EqualSpacing,
                Spacing      = 0
            };

            var scroll = new UIScrollView {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            Add(scroll);

            scroll.AddSubview(_stackView);
            scroll.FullSizeOf(View);

            _stackView.FullSizeOf(scroll);
            _stackView.WidthAnchor.ConstraintEqualTo(scroll.WidthAnchor).Active = true;

            _tree = GetTree();
            _tree.ForEach(node => _stackView.AddArrangedSubview(new NodeView(node, ToggleNode)));
        }
Exemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Create and add Views

            var stackView = new UIStackView
            {
                Axis = UILayoutConstraintAxis.Vertical,
                // make the inner views to fill the whole available width
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.EqualSpacing,
                // margin between views
                Spacing = 4,
                // apply padding between the parent view (the scroll) and the stack
                LayoutMargins = new UIEdgeInsets(4, 4, 4, 4),
                // this will make padding actually work
                LayoutMarginsRelativeArrangement = true
            };

            var scroll = new UIScrollView();

            Add(scroll);

            scroll.AddSubview(stackView);

            // Add some views to the stack with random height and color
            // Notice that we use AddArrangedSubview rather than the former AddSubview
            // for UIStackView to manage it. Otherwise it won´t work
            for (var i = 0; i < 20; i++)
            {
                stackView.AddArrangedSubview(GetRandomView());
            }

            // Layout Views

            // For AutoLayout to work, all views and nested views need to set its
            // "TranslatesAutoresizingMaskIntoConstraints" property to true. It´s easy
            // to forget it so I created an extension method that will set it to the view
            // and its subviews
            scroll.EnableAutoLayout();

            // "FullSizeOf" is a method extension to set leading, trailing,
            // bottom and top constraints
            scroll.FullSizeOf(View);
            stackView.FullSizeOf(scroll);

            // constraint needed when the UIStackView is inside the UIScrollView
            stackView.WidthAnchor.ConstraintEqualTo(scroll.WidthAnchor).Active = true;
        }
Exemplo n.º 4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _container = new UIView {
                BackgroundColor = UIColor.White
            }
            .AddTo(View);

            _container.ActivateConstraints(
                _container.LeadingAnchor.ConstraintEqualTo(View.LeadingAnchor),
                _container.TrailingAnchor.ConstraintEqualTo(View.TrailingAnchor),
                _container.BottomAnchor.ConstraintEqualTo(View.BottomAnchor),
                _container.HeightAnchor.ConstraintEqualTo(120)
                );

            _okButton = new UIButton(UIButtonType.System)
                        .AddTo(_container)
                        .SetButtonTitle("Done");

            _okButton.ActivateConstraints(
                _okButton.RightAnchor.ConstraintEqualTo(_container.RightAnchor, -12),
                _okButton.TopAnchor.ConstraintEqualTo(_container.TopAnchor, 4)
                );

            var scroll = new UIScrollView
            {
                ContentInset = new UIEdgeInsets(0, 10, 0, 10),
                ShowsHorizontalScrollIndicator = false,
                Bounces = false
            }.AddTo(_container);

            scroll.FullSizeOf(_container, new UIEdgeInsets(35, 0, 0, 0));

            _stack = new UIStackView
            {
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.EqualSpacing,
                Spacing      = 4
            }.AddTo(scroll);

            _stack.FullSizeOf(scroll);

            foreach (var option in _options)
            {
                _stack.AddArrangedSubview(new ToggleButton(option.Key, option.Value, 50, 75));
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Main scrolled stack

            var stackView = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis          = UILayoutConstraintAxis.Vertical,
                Alignment     = UIStackViewAlignment.Fill,
                Distribution  = UIStackViewDistribution.EqualSpacing,
                Spacing       = 4,
                LayoutMargins = new UIEdgeInsets(4, 4, 4, 4), // apply padding
                LayoutMarginsRelativeArrangement = true       // apply padding
            };

            var scroll = new UIScrollView {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            Add(scroll);

            scroll.AddSubview(stackView);
            scroll.FullSizeOf(View);

            stackView.FullSizeOf(scroll);
            stackView.WidthAnchor.ConstraintEqualTo(scroll.WidthAnchor).Active = true;

            // Nested stacks

            var nested1 = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.FillEqually,
                Spacing      = 4
            };

            var nested2 = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.EqualSpacing,
                Spacing      = 4
            };

            var nested3 = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.FillProportionally,
                Spacing      = 4
            };

            var nested4 = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Top,
                Distribution = UIStackViewDistribution.EqualCentering,
                Spacing      = 4
            };

            var nested5 = new UIStackView
            {
                TranslatesAutoresizingMaskIntoConstraints = false,
                Axis         = UILayoutConstraintAxis.Horizontal,
                Alignment    = UIStackViewAlignment.Fill,
                Distribution = UIStackViewDistribution.EqualSpacing,
                Spacing      = 4
            };

            for (var i = 0; i < 3; i++)
            {
                nested1.AddArrangedSubview(GetRandomView());
                nested2.AddArrangedSubview(GetRandomView());
                nested3.AddArrangedSubview(GetRandomView());
                nested4.AddArrangedSubview(GetRandomView(50, 15 * (i + 1)));
            }

            stackView.AddArrangedSubview(GetNestedStackContainer("Fill Equally", nested1));
            stackView.AddArrangedSubview(GetNestedStackContainer("Equal Spacing", nested2));
            stackView.AddArrangedSubview(GetNestedStackContainer("Fill Proportionally", nested3));

            for (var i = 0; i < 30; i++)
            {
                nested5.AddArrangedSubview(GetRandomView());
            }

            var nestedScroll = new UIScrollView {
                TranslatesAutoresizingMaskIntoConstraints = false
            };

            nestedScroll.AddSubview(nested5);

            stackView.AddArrangedSubview(GetNestedStackContainer("Nested stack with scroll", nestedScroll));

            nested5.FullSizeOf(nestedScroll);
            nested5.HeightAnchor.ConstraintEqualTo(nestedScroll.HeightAnchor).Active = true;

            stackView.AddArrangedSubview(GetNestedStackContainer("Align Top", nested4));
        }