/// <summary>
        /// <para>Constrains the layout of subviews according to equations and
        /// inequalities specified in <paramref name="constraints"/>.  Issue
        /// multiple constraints per call using the &amp;&amp; operator.</para>
        /// <para>e.g. button.Frame.Left &gt;= text.Frame.Right + 22 &amp;&amp;
        /// button.Frame.Width == View.Frame.Width * 0.42f</para>
        /// </summary>
        /// <param name="view">The superview laying out the referenced subviews.</param>
        /// <param name="constraints">Constraint equations and inequalities.</param>
        public static void ConstrainLayout(this UIView view, Expression<Func<bool>> constraints)
        {
            var body = ((LambdaExpression)constraints).Body;

            var exprs = new List<BinaryExpression> ();
            FindConstraints (body, exprs);

            view.AddConstraints (exprs.Select (CompileConstraint).ToArray ());
        }
Beispiel #2
0
        /// <summary>
        /// <para>Constrains the layout of subviews according to equations and
        /// inequalities specified in <paramref name="constraints"/>.  Issue
        /// multiple constraints per call using the &amp;&amp; operator.</para>
        /// <para>e.g. button.Frame.Left &gt;= text.Frame.Right + 22 &amp;&amp;
        /// button.Frame.Width == View.Frame.Width * 0.42f</para>
        /// </summary>
        /// <param name="view">The superview laying out the referenced subviews.</param>
        /// <param name="constraints">Constraint equations and inequalities.</param>
        /// <param name = "priority">The priority of the constraints</param>
        public static NSLayoutConstraint[] ConstrainLayout (this UIView view, Expression<Func<bool>> constraints, UILayoutPriority priority)
        {
            var body = constraints.Body;

            var exprs = new List<BinaryExpression> ();
            FindConstraints (body, exprs);

            var layoutConstraints = exprs.Select (e => CompileConstraint (e, view)).ToArray ();

            if (layoutConstraints.Length > 0) {
                foreach (var c in layoutConstraints) {
                    c.Priority = (float)priority;
                }
                view.AddConstraints (layoutConstraints);
            }

            return layoutConstraints;
        }
 public static void AddConstraints(this UIView view, IEnumerable<FluentLayout> fluentLayouts)
 {
     view.AddConstraints(fluentLayouts
                             .SelectMany(fluent => fluent.ToLayoutConstraints())
                             .ToArray());
 }
 public static void AddConstraints(this UIView view, params FluentLayout[] fluentLayouts)
 {
     view.AddConstraints(fluentLayouts
                             .SelectMany(fluent => fluent.ToLayoutConstraints())
                             .ToArray());
 }
        private static TypeParameterConstraintClauseSyntax AddConstraint(
            this TypeParameterConstraintClauseSyntax @this,
            TypeParameterConstraintSyntax @typeParameterConstraintSyntax)
        {
            var result = @this.Constraints
                .Any(x => x == @typeParameterConstraintSyntax);

            if (result)
                return @this;

            return @this.AddConstraints(
                @typeParameterConstraintSyntax);
        }