Beispiel #1
0
		static public NSLayoutConstraint [] FromVisualFormat (string format, NSLayoutFormatOptions formatOptions, params object [] viewsAndMetrics)
		{
			NSMutableDictionary views = null, metrics = null;
			var count = viewsAndMetrics.Length;
			if (count != 0){
				if ((count % 2) != 0)
					throw new ArgumentException ("You should provide pairs and values, the parameter passed is not even", "viewsAndMetrics");

				for (int i = 0; i < count; i+=2){
					var key = viewsAndMetrics [i];
					NSString nskey;

					if (key is string)
						nskey = new NSString ((string)key);
					else if (key is NSString)
						nskey = (NSString) key;
					else 
						throw new ArgumentException (String.Format ("Item at {0} is not a string or an NSString", i), "viewsAndMetrics");
					
					var value = viewsAndMetrics [i+1];
					if (value is View){
						if (views == null)
							views = new NSMutableDictionary ();
						views [nskey] = (NSObject) value;
						continue;
					} else if (value is INativeObject && Messaging.bool_objc_msgSend_IntPtr (((INativeObject) value).Handle, Selector.GetHandle ("isKindOfClass:"), Class.GetHandle (typeof (View)))) {
						if (views == null)
							views = new NSMutableDictionary ();
						views.LowlevelSetObject (((INativeObject) value).Handle, nskey.Handle);
						continue;
					}
#if !MONOMAC
					// This requires UILayoutSupport class which is not exist on Mac
					else if (value is INativeObject && Messaging.bool_objc_msgSend_IntPtr (((INativeObject) value).Handle, Selector.GetHandle ("conformsToProtocol:"), Protocol.GetHandle (typeof (UILayoutSupport).Name))) {
						if (views == null)
							views = new NSMutableDictionary ();
						views.LowlevelSetObject (((INativeObject) value).Handle, nskey.Handle);
						continue;
					}
#endif // !MONOMAC

					var number = AsNumber (value);
					if (number == null)
						throw new ArgumentException (String.Format ("Item at {0} is not a number or a view", i+1), "viewsAndMetrics");
					if (metrics == null)
						metrics = new NSMutableDictionary ();
					metrics [nskey] = number;
				}
			}
			if (views == null)
				throw new ArgumentException ("You should at least provide a pair of name, view", "viewAndMetrics");
			
			return FromVisualFormat (format, formatOptions, metrics, views);
		}
Beispiel #2
0
        public static NSLayoutConstraint[] Constraint(string format, NSLayoutFormatOptions options, NSDictionary metrics, NSDictionary views)
        {
            foreach (var entry in views)
            {
                var v = entry.Value as UIView;
                if (v != null)
                {
                    v.TranslatesAutoresizingMaskIntoConstraints = false;
                }
            }
            ;

            return(NSLayoutConstraint.FromVisualFormat(
                       format: format,
                       formatOptions: options,
                       metrics: metrics,
                       views: views
                       ));
        }
Beispiel #3
0
 public static NSLayoutConstraint [] StackVertical(float padding, NSLayoutFormatOptions options, params NSView [] views)
 {
     return(NSLayoutExtensions.Stack(StackOrientation.Vertical, padding, options, views));
 }
Beispiel #4
0
        static NSLayoutConstraint [] Stack(StackOrientation orientation, float padding, NSLayoutFormatOptions options, params NSView [] views)
        {
            var names           = views.Select((view, index) => $"{view.Identifier}__{index}");
            var orientIndicator = orientation == StackOrientation.Horizontal ? "H:" : "V:";
            var separator       = padding < 0 ? "-" : $"-({padding})-";
            var vfl             = string.Join(separator, names.Select(name => $"[{name}]"));
            var objects         = new List <object> ();

            for (var i = 0; i < views.Length; i++)
            {
                objects.Add(names.ElementAt(i));
                objects.Add(views [i]);
            }

            return(NSLayoutConstraint.FromVisualFormat(orientIndicator + vfl, options, objects.ToArray()));
        }
Beispiel #5
0
 public static NSLayoutConstraint [] VerticalSpaceBetween(NSView topView, NSView bottomView, NSLayoutFormatOptions options, NSLayoutPriority priority)
 {
     return(NSLayoutConstraint.FromVisualFormat($"V:[top]-(>=0@{(float)priority})-[bottom]", options, "top", topView, "bottom", bottomView));
 }
Beispiel #6
0
 public static NSLayoutConstraint [] VerticalSpaceBetween(NSView topView, NSView bottomView, NSLayoutFormatOptions options)
 {
     return(NSLayoutConstraint.FromVisualFormat("V:[top]-(>=0)-[bottom]", options, "top", topView, "bottom", bottomView));
 }
Beispiel #7
0
 public static NSLayoutConstraint [] HorizontalSpaceBetween(NSView leftView, NSView rightView, NSLayoutFormatOptions options)
 {
     return(NSLayoutConstraint.FromVisualFormat("[left]-(>=0)-[right]", options, "left", leftView, "right", rightView));
 }
Beispiel #8
0
        static public NSLayoutConstraint [] FromVisualFormat(string format, NSLayoutFormatOptions formatOptions, params object [] viewsAndMetrics)
        {
            NSMutableDictionary views = null, metrics = null;
            var count = viewsAndMetrics.Length;

            if (count != 0)
            {
                if ((count % 2) != 0)
                {
                    throw new ArgumentException("You should provide pairs and values, the parameter passed is not even", "viewsAndMetrics");
                }

                for (int i = 0; i < count; i += 2)
                {
                    var      key = viewsAndMetrics [i];
                    NSString nskey;

                    if (key is string)
                    {
                        nskey = new NSString((string)key);
                    }
                    else if (key is NSString)
                    {
                        nskey = (NSString)key;
                    }
                    else
                    {
                        throw new ArgumentException(String.Format("Item at {0} is not a string or an NSString", i), "viewsAndMetrics");
                    }

                    var value = viewsAndMetrics [i + 1];
                    if (value is View)
                    {
                        if (views == null)
                        {
                            views = new NSMutableDictionary();
                        }
                        views [nskey] = (NSObject)value;
                        continue;
                    }
                    else if (value is INativeObject && Messaging.bool_objc_msgSend_IntPtr(((INativeObject)value).Handle, Selector.GetHandle("isKindOfClass:"), Class.GetHandle(typeof(View))))
                    {
                        if (views == null)
                        {
                            views = new NSMutableDictionary();
                        }
                        views.LowlevelSetObject(((INativeObject)value).Handle, nskey.Handle);
                        continue;
                    }
#if !MONOMAC
                    // This requires UILayoutSupport class which is not exist on Mac
                    else if (value is INativeObject && Messaging.bool_objc_msgSend_IntPtr(((INativeObject)value).Handle, Selector.GetHandle("conformsToProtocol:"), Protocol.GetHandle(typeof(UILayoutSupport).Name)))
                    {
                        if (views == null)
                        {
                            views = new NSMutableDictionary();
                        }
                        views.LowlevelSetObject(((INativeObject)value).Handle, nskey.Handle);
                        continue;
                    }
#endif // !MONOMAC

                    var number = AsNumber(value);
                    if (number == null)
                    {
                        throw new ArgumentException(String.Format("Item at {0} is not a number or a view", i + 1), "viewsAndMetrics");
                    }
                    if (metrics == null)
                    {
                        metrics = new NSMutableDictionary();
                    }
                    metrics [nskey] = number;
                }
            }
            if (views == null)
            {
                throw new ArgumentException("You should at least provide a pair of name, view", "viewAndMetrics");
            }

            return(FromVisualFormat(format, formatOptions, metrics, views));
        }
Beispiel #9
0
 public static AnyObject[] ConstraintsWithVisualFormat(string format, NSLayoutFormatOptions options, Dictionary <NSObject, AnyObject> metrics, Dictionary <NSObject, AnyObject> views)
 {
     return(default(AnyObject[]));
 }
Beispiel #10
0
 public static void AddUniversalConstraints(this UIView view, string format, NSLayoutFormatOptions options = default(NSLayoutFormatOptions), NSDictionary metrics = null, NSDictionary views = null)
 {
     view.AddConstraints(NSLayoutConstraint.FromVisualFormat(String.Format("H:{0}", format), options, metrics, views));
     view.AddConstraints(NSLayoutConstraint.FromVisualFormat(String.Format("V:{0}", format), options, metrics, views));
 }
Beispiel #11
0
 public static void AddConstraints(this UIView view, string format, NSLayoutFormatOptions options, NSDictionary metrics, NSDictionary views)
 {
     view.AddConstraints(NSLayoutConstraint.FromVisualFormat(format, options, metrics, views));
 }
Beispiel #12
0
        //For adding a constraints between a single parent view and child view
        public void AddConstraintToView(UIView parentView, UIView childView, string childViewName, string constraint, NSLayoutFormatOptions formatOptions)
        {
            var viewDictionary = NSDictionary.FromObjectsAndKeys(new NSObject[] { childView }, new NSObject[] { new NSString(childViewName) });

            parentView.AddConstraints(NSLayoutConstraint.FromVisualFormat(constraint, formatOptions, new NSDictionary(), viewDictionary));
        }