Example #1
0
        /// <summary>
        /// Eliminates the needs to implement the UIScrollView in the xib.
        /// You can build out the screens as necessary, then call this method to
        /// wrap the view in a scroll view.
        ///
        /// NOTE: The controls in the xib MUST have top to bottom constraints in
        /// order for the scroll view to determine it's vertical content size.
        /// Usually, this can be done by adding a ">= NUM" constraint on the last
        /// control to the superview's bottom.
        /// </summary>
        public static void MakeScrollable(this UIViewController viewController, UIColor backgroundColor)
        {
            var contentView = viewController.View;

            contentView.BackgroundColor = backgroundColor;
            var newView = new UIView {
                BackgroundColor = backgroundColor
            };
            var scrollView = new UIScrollView();

            newView.AddSubview(scrollView);
            scrollView.AddConstraintsToFillSuperview();

            scrollView.AddSubview(contentView);
            contentView.AddConstraintsToFillSuperview();

            contentView.WidthAnchor.ConstraintEqualTo(newView.WidthAnchor).Active = true;

            viewController.View = newView;
        }