/// <summary>
        /// Generates a <see cref="UIStackView"/> given the specified <see cref="UILayoutConstraintAxis"/>,
        /// <see cref="UIStackViewAlignment"/>, <see cref="UIStackViewDistribution"/>, spacing and sub-views.
        /// </summary>
        /// <param name="axis">The specified <see cref="UILayoutConstraintAxis"/>.</param>
        /// <param name="alignment">The specified <see cref="UIStackViewAlignment"/>.</param>
        /// <param name="distribution">The specified <see cref="UIStackViewDistribution"/>.</param>
        /// <param name="spacing">The specified spacing.</param>
        /// <param name="subViews">The specified sub-views.</param>
        /// <returns>The generated <see cref="UIStackView"/>.</returns>
        public static UIStackView GenerateStackView(UILayoutConstraintAxis axis, UIStackViewAlignment alignment,
                                                    UIStackViewDistribution distribution, nfloat spacing, IEnumerable <UIView> subViews)
        {
            if (subViews == null)
            {
                throw new ArgumentNullException();
            }

            var stackView = new UIStackView
            {
                Axis         = axis,
                Alignment    = alignment,
                Distribution = distribution,
                Spacing      = spacing
            };

            foreach (var subView in subViews)
            {
                stackView.AddArrangedSubview(subView);
            }

            stackView.TranslatesAutoresizingMaskIntoConstraints = false;
            stackView.SizeToFit();
            stackView.LayoutIfNeeded();

            ConfigureStackViewAccessibilityAttributes(stackView);
            return(stackView);
        }
Example #2
0
 /// <summary>
 /// Set alignment of UIStackView.
 /// </summary>
 public static UIStackView Alignment(this UIStackView stackView, UIStackViewAlignment alignment)
 {
     stackView.Alignment = alignment;
     return(stackView);
 }