Example #1
0
        /// <summary>
        /// Constraint height anchor with a constant.
        /// </summary>
        public static T ConstraintHeightEqualTo <T>(this T view, nfloat constant, LayoutConstraints constraints = default) where T : UIView
        {
            var heightConstraint = view.HeightAnchor.ConstraintEqualTo(constant);

            if (constraints != null)
            {
                constraints.Height = heightConstraint;
            }
            heightConstraint.Active = true;
            return(view);
        }
Example #2
0
        /// <summary>
        /// Constraint width anchor with a constant.
        /// </summary>
        public static T ConstraintWidthEqualTo <T>(this T view, nfloat constant, LayoutConstraints constraints = default) where T : UIView
        {
            var widthConstraint = view.WidthAnchor.ConstraintEqualTo(constant);

            if (constraints != null)
            {
                constraints.Width = widthConstraint;
            }
            widthConstraint.Active = true;
            return(view);
        }
Example #3
0
        /// <summary>
        /// Constraint centreY anchor to an anchor.
        /// </summary>
        public static T ConstraintCentreYEqualTo <T>(this T view, NSLayoutYAxisAnchor anchor, nfloat constant = default, LayoutConstraints constraints = default) where T : UIView
        {
            var centerYConstraint = view.CenterYAnchor.ConstraintEqualTo(anchor, constant);

            if (constraints != null)
            {
                constraints.CenterY = centerYConstraint;
            }
            centerYConstraint.Active = true;
            return(view);
        }
Example #4
0
        /// <summary>
        /// Constraint bottom anchor to an anchor.
        /// </summary>
        public static T ConstraintBottomEqualTo <T>(this T view, NSLayoutYAxisAnchor anchor, nfloat constant = default, LayoutConstraints constraints = default) where T : UIView
        {
            var bottomConstraint = view.BottomAnchor.ConstraintEqualTo(anchor, -constant);

            if (constraints != null)
            {
                constraints.Bottom = bottomConstraint;
            }
            bottomConstraint.Active = true;
            return(view);
        }
Example #5
0
        /// <summary>
        /// Constraint trailing anchor to an anchor.
        /// </summary>
        public static T ConstraintTrailingEqualTo <T>(this T view, NSLayoutXAxisAnchor anchor, nfloat constant = default, LayoutConstraints constraints = default) where T : UIView
        {
            var trailingConstraint = view.TrailingAnchor.ConstraintEqualTo(anchor, -constant);

            if (constraints != null)
            {
                constraints.Trailing = trailingConstraint;
            }
            trailingConstraint.Active = true;
            return(view);
        }
Example #6
0
        /// <summary>
        /// Constraint top anchor to an anchor.
        /// </summary>
        public static T ConstraintTopEqualTo <T>(this T view, NSLayoutYAxisAnchor anchor, nfloat constant = default, LayoutConstraints constraints = default) where T : UIView
        {
            var topConstraint = view.TopAnchor.ConstraintEqualTo(anchor, constant);

            if (constraints != null)
            {
                constraints.Top = topConstraint;
            }
            topConstraint.Active = true;
            return(view);
        }
Example #7
0
 /// <summary>
 /// Center in superview by constraining centerX and centerY to superview, respectively.
 /// </summary>
 public static T AnchorCenter <T>(this T view, UIOffset offset = default, CGSize size = default, LayoutConstraints constraints = default) where T : UIView
 {
     return(view.ActivateConstaints()
            .ConstraintCentreXEqualTo(view.Superview.CenterXAnchor, offset.Horizontal, constraints)
            .ConstraintCentreYEqualTo(view.Superview.CenterYAnchor, offset.Vertical, constraints)
            .ConstraintWidthEqualTo(size.Width, constraints)
            .ConstraintHeightEqualTo(size.Height, constraints));
 }
Example #8
0
 /// <summary>
 /// Fill superview by constraining leading, top, trailing and bottom to superview.
 /// </summary>
 public static T AnchorFill <T>(this T view, UIEdgeInsets edgeInsets = default, LayoutConstraints constraints = default) where T : UIView
 {
     return(view.ActivateConstaints()
            .ConstraintLeadingEqualTo(view.Superview.LeadingAnchor, edgeInsets.Left, constraints)
            .ConstraintTopEqualTo(view.Superview.TopAnchor, edgeInsets.Top, constraints)
            .ConstraintTrailingEqualTo(view.Superview.TrailingAnchor, edgeInsets.Right, constraints)
            .ConstraintBottomEqualTo(view.Superview.BottomAnchor, edgeInsets.Bottom, constraints));
 }
Example #9
0
        /// <summary>
        /// Constraint height anchor to an anchor.
        /// </summary>
        public static T ConstraintHeightEqualTo <T>(this T view, NSLayoutAnchor <NSLayoutDimension> anchor, LayoutConstraints constraints = default) where T : UIView
        {
            var heightConstraint = view.HeightAnchor.ConstraintEqualTo(anchor);

            if (constraints != null)
            {
                constraints.Height = heightConstraint;
            }
            heightConstraint.Active = true;
            return(view);
        }
Example #10
0
        /// <summary>
        /// Constraint width anchor to an anchor.
        /// </summary>
        public static T ConstraintWidthEqualTo <T>(this T view, NSLayoutAnchor <NSLayoutDimension> anchor, LayoutConstraints constraints = default) where T : UIView
        {
            var widthConstraint = view.WidthAnchor.ConstraintEqualTo(anchor);
            var test            = new UIView();

            if (constraints != null)
            {
                constraints.Width = widthConstraint;
            }
            widthConstraint.Active = true;
            return(view);
        }