void PlanetSizes() { NSLayoutConstraint mercuryHeight = mercury.HeightAnchor.ConstraintEqualToAnchor(earth.HeightAnchor, .38f); NSLayoutConstraint mercuryWidth = mercury.WidthAnchor.ConstraintEqualToAnchor(mercury.HeightAnchor, 1f); NSLayoutConstraint venusHeight = venus.HeightAnchor.ConstraintEqualToAnchor(earth.HeightAnchor, .95f); NSLayoutConstraint venusWidth = venus.WidthAnchor.ConstraintEqualToAnchor(venus.HeightAnchor, 1f); NSLayoutConstraint marsHeight = mars.HeightAnchor.ConstraintEqualToAnchor(earth.HeightAnchor, .53f); NSLayoutConstraint marsWidth = mars.WidthAnchor.ConstraintEqualToAnchor(mars.HeightAnchor, 1f); NSLayoutConstraint jupiterHeight = jupiter.HeightAnchor.ConstraintEqualToAnchor(earth.HeightAnchor, 11.2f); NSLayoutConstraint jupiterWidth = jupiter.WidthAnchor.ConstraintEqualToAnchor(jupiter.HeightAnchor, 1f); NSLayoutConstraint saturnHeight = saturn.HeightAnchor.ConstraintEqualToAnchor(earth.HeightAnchor, 9.45f); NSLayoutConstraint saturnWidth = saturn.WidthAnchor.ConstraintEqualToAnchor(saturn.HeightAnchor, 1.5f); NSLayoutConstraint uranusHeight = uranus.HeightAnchor.ConstraintEqualToAnchor(earth.HeightAnchor, 4f); NSLayoutConstraint uranusWidth = uranus.WidthAnchor.ConstraintEqualToAnchor(uranus.HeightAnchor, 1f); NSLayoutConstraint neptuneHeight = neptune.HeightAnchor.ConstraintEqualToAnchor(earth.HeightAnchor, 3.88f); NSLayoutConstraint neptuneWidth = neptune.HeightAnchor.ConstraintEqualToAnchor(neptune.HeightAnchor, 1f); NSLayoutConstraint earthWidth = earth.WidthAnchor.ConstraintEqualToAnchor(earth.HeightAnchor); mercuryHeight.SetIdentifier("mercuryHeight"); mercuryHeight.SetIdentifier("mercuryHeight"); mercuryWidth.SetIdentifier("mercuryWidth"); venusHeight.SetIdentifier("venusHeight"); venusWidth.SetIdentifier("venusWidth"); marsHeight.SetIdentifier("marsHeight"); marsWidth.SetIdentifier("marsWidth"); jupiterHeight.SetIdentifier("jupiterHeight"); jupiterWidth.SetIdentifier("jupiterWidth"); saturnHeight.SetIdentifier("saturnHeight"); saturnWidth.SetIdentifier("saturnWidth"); uranusHeight.SetIdentifier("uranusHeight"); uranusWidth.SetIdentifier("uranusWidth"); neptuneHeight.SetIdentifier("neptuneHeight"); neptuneWidth.SetIdentifier("neptuneWidth"); earthWidth.SetIdentifier("earthWidth"); NSLayoutConstraint.ActivateConstraints(new [] { mercuryHeight, venusHeight, marsHeight, jupiterHeight, saturnHeight, uranusHeight, neptuneHeight, mercuryWidth, venusWidth, earthWidth, marsWidth, jupiterWidth, saturnWidth, uranusWidth, neptuneWidth }); }
NSLayoutConstraint GuideHeightToPlanet(UILayoutGuide layoutGuide, UIView planet, string identifier) { NSLayoutConstraint guideHeightToPlanet = layoutGuide.HeightAnchor.ConstraintEqualToAnchor(planet.HeightAnchor); guideHeightToPlanet.SetIdentifier(identifier); return(guideHeightToPlanet); }
NSLayoutConstraint CreateCenterXConstraint(UIView planetToCenter, string identifierName) { NSLayoutConstraint newConstraint = planetToCenter.CenterXAnchor.ConstraintEqualToAnchor(View.CenterXAnchor); newConstraint.SetIdentifier(identifierName); return(newConstraint); }
void setupKludge() { if (this.kludge == null) { UIView kludge1 = new UIView(); kludge1.BackgroundColor = UIColor.Yellow; this.View.AddSubview(kludge1); kludge1.TranslatesAutoresizingMaskIntoConstraints = false; kludge1.Hidden = true; NSLayoutConstraint a = NSLayoutConstraint.Create(view1: kludge1, attribute1: NSLayoutAttribute.Left, relation: NSLayoutRelation.Equal, view2: this.View, attribute2: NSLayoutAttribute.Left, multiplier: 1, constant: 0); NSLayoutConstraint b = NSLayoutConstraint.Create(view1: kludge1, attribute1: NSLayoutAttribute.Right, relation: NSLayoutRelation.Equal, view2: this.View, attribute2: NSLayoutAttribute.Left, multiplier: 1, constant: 0); NSLayoutConstraint c = NSLayoutConstraint.Create(view1: kludge1, attribute1: NSLayoutAttribute.Top, relation: NSLayoutRelation.Equal, view2: this.View, attribute2: NSLayoutAttribute.Top, multiplier: 1, constant: 0); NSLayoutConstraint d = NSLayoutConstraint.Create(view1: kludge1, attribute1: NSLayoutAttribute.Bottom, relation: NSLayoutRelation.Equal, view2: this.View, attribute2: NSLayoutAttribute.Top, multiplier: 1, constant: 0); a.SetIdentifier("idHCa"); b.SetIdentifier("idHCa"); c.SetIdentifier("idHCc"); d.SetIdentifier("idHCd"); this.View.AddConstraints(new NSLayoutConstraint[] { a, b, c, d }); this.kludge = kludge1; } //Console.WriteLine("Kludge is not created"); }
public static NSLayoutConstraint WithIdentifier(this NSLayoutConstraint constraint, string id) { if (constraint == null) { throw new ArgumentNullException(nameof(constraint)); } if (id == null) { throw new ArgumentNullException(nameof(id)); } constraint.SetIdentifier(id); return(constraint); }
public static NSLayoutConstraint UpdateMultiplier(this NSLayoutConstraint constraint, nfloat multiplier) { NSObject firstItem = constraint.FirstItem; NSObject secondItem = constraint.SecondItem; NSLayoutAttribute firstAttribute = constraint.FirstAttribute; NSLayoutAttribute secondAttribute = constraint.SecondAttribute; NSLayoutConstraint newConstraint = NSLayoutConstraint.Create(firstItem, firstAttribute, constraint.Relation, secondItem, secondAttribute, multiplier, constraint.Constant); newConstraint.Priority = constraint.Priority; newConstraint.ShouldBeArchived = constraint.ShouldBeArchived; newConstraint.SetIdentifier(constraint.GetIdentifier()); newConstraint.Active = true; NSLayoutConstraint.DeactivateConstraints(new NSLayoutConstraint[] { constraint }); NSLayoutConstraint.DeactivateConstraints(new NSLayoutConstraint[] { newConstraint }); return(newConstraint); }
void CreateRegularConstraints () { if (regularConstraints?.Length > 0 && sharedConstraints?.Count > 0) return; UILayoutGuide leadingMercuryGuide = NewLayoutGuide ("leadingMercuryGuide"); UILayoutGuide leadingVenusGuide = NewLayoutGuide ("leadingVenusGuide"); UILayoutGuide leadingEarthGuide = NewLayoutGuide ("leadingEarthGuide"); UILayoutGuide leadingMarsGuide = NewLayoutGuide ("leadingMarsGuide"); UILayoutGuide leadingJupiterGuide = NewLayoutGuide ("leadingJupiterGuide"); UILayoutGuide leadingSaturnGuide = NewLayoutGuide ("leadingSaturnGuide"); UILayoutGuide leadingUranusGuide = NewLayoutGuide ("leadingUranusGuide"); UILayoutGuide leadingNeptuneGuide = NewLayoutGuide ("leadingNeptuneGuide"); UILayoutGuide trailingMercuryGuide = NewLayoutGuide ("trailingMercuryGuide"); UILayoutGuide trailingVenusGuide = NewLayoutGuide ("trailingVenusGuide"); UILayoutGuide trailingEarthGuide = NewLayoutGuide ("trailingEarthGuide"); UILayoutGuide trailingMarsGuide = NewLayoutGuide ("trailingMarsGuide"); UILayoutGuide trailingJupiterGuide = NewLayoutGuide ("trailingJupiterGuide"); UILayoutGuide trailingSaturnGuide = NewLayoutGuide ("trailingSaturnGuide"); UILayoutGuide trailingUranusGuide = NewLayoutGuide ("trailingUranusGuide"); UILayoutGuide trailingNeptuneGuide = NewLayoutGuide ("trailingNeptuneGuide"); IUILayoutSupport topLayoutGuide = TopLayoutGuide; var planetsAndGuides = NSDictionary.FromObjectsAndKeys (new object[] { mercury, venus, earth, mars, jupiter, saturn, uranus, neptune, leadingMercuryGuide, leadingVenusGuide, leadingEarthGuide, leadingMarsGuide, leadingJupiterGuide, leadingSaturnGuide, leadingUranusGuide, leadingNeptuneGuide, trailingMercuryGuide, trailingVenusGuide, trailingEarthGuide, trailingMarsGuide, trailingJupiterGuide, trailingSaturnGuide, trailingUranusGuide, trailingNeptuneGuide, topLayoutGuide }, new object[] { "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "leadingMercuryGuide", "leadingVenusGuide", "leadingEarthGuide", "leadingMarsGuide", "leadingJupiterGuide", "leadingSaturnGuide", "leadingUranusGuide", "leadingNeptuneGuide", "trailingMercuryGuide", "trailingVenusGuide", "trailingEarthGuide", "trailingMarsGuide", "trailingJupiterGuide", "trailingSaturnGuide", "trailingUranusGuide", "trailingNeptuneGuide", "topLayoutGuide" }); var topToBottom = NSLayoutConstraint.FromVisualFormat ("V:|[topLayoutGuide]-[leadingMercuryGuide]-" + "[leadingVenusGuide]-[leadingEarthGuide]-[leadingMarsGuide]-" + "[leadingJupiterGuide][leadingSaturnGuide][leadingUranusGuide]-" + "[leadingNeptuneGuide]-20-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, planetsAndGuides); sharedConstraints = new List<NSLayoutConstraint> (topToBottom); SetLayoutIdentifierForArray ((NSString)"topToBottom", NSArray.FromObjects (topToBottom)); NewHorizontalArray ("|[leadingMercuryGuide][mercury][trailingMercuryGuide]|", "hMercury", planetsAndGuides); NewHorizontalArray ("|[leadingVenusGuide][venus][trailingVenusGuide]|", "hVenus", planetsAndGuides); NewHorizontalArray ("|[leadingEarthGuide][earth][trailingEarthGuide]|", "hEarth", planetsAndGuides); NewHorizontalArray ("|[leadingMarsGuide][mars][trailingMarsGuide]|", "hMars", planetsAndGuides); NewHorizontalArray ("|[leadingJupiterGuide][jupiter][trailingJupiterGuide]|", "hJupiter", planetsAndGuides); NewHorizontalArray ("|[leadingSaturnGuide][saturn][trailingSaturnGuide]|", "hSaturn", planetsAndGuides); NewHorizontalArray ("|[leadingUranusGuide][uranus][trailingUranusGuide]|", "hUranus", planetsAndGuides); NewHorizontalArray ("|[leadingNeptuneGuide][neptune][trailingNeptuneGuide]|", "hNeptune", planetsAndGuides); sharedConstraints.Add (GuideHeightToPlanet (leadingMercuryGuide, mercury, "guideHeightToMercury")); sharedConstraints.Add (GuideHeightToPlanet (leadingVenusGuide, venus, "guideHeightToVenus")); sharedConstraints.Add (GuideHeightToPlanet (leadingEarthGuide, earth, "guideHeightToEarth")); sharedConstraints.Add (GuideHeightToPlanet (leadingMarsGuide, mars, "guideHeightToMars")); sharedConstraints.Add (GuideHeightToPlanet (leadingJupiterGuide, jupiter, "guideHeightToJupiter")); sharedConstraints.Add (GuideHeightToPlanet (leadingSaturnGuide, saturn, "guideHeightToSaturn")); sharedConstraints.Add (GuideHeightToPlanet (leadingUranusGuide, uranus, "guideHeightToUranus")); sharedConstraints.Add (GuideHeightToPlanet (leadingNeptuneGuide, neptune, "guideHeightToNeptune")); mercuryLeadingToTrailing = leadingMercuryGuide.WidthAnchor.ConstraintEqualTo (trailingMercuryGuide.WidthAnchor, .02f); venusLeadingToTrailing = leadingVenusGuide.WidthAnchor.ConstraintEqualTo (trailingVenusGuide.WidthAnchor, .03f); earthLeadingToTrailing = leadingEarthGuide.WidthAnchor.ConstraintEqualTo (trailingEarthGuide.WidthAnchor, .06f); marsLeadingToTrailing = leadingMarsGuide.WidthAnchor.ConstraintEqualTo (trailingMarsGuide.WidthAnchor, .1f); jupiterLeadingToTrailing = leadingJupiterGuide.WidthAnchor.ConstraintEqualTo (trailingJupiterGuide.WidthAnchor, .2f); saturnLeadingToTrailing = leadingSaturnGuide.WidthAnchor.ConstraintEqualTo (trailingSaturnGuide.WidthAnchor, 1f); uranusLeadingToTrailing = leadingUranusGuide.WidthAnchor.ConstraintEqualTo (trailingUranusGuide.WidthAnchor, 2.7f); neptuneLeadingToTrailing = leadingNeptuneGuide.WidthAnchor.ConstraintEqualTo (trailingNeptuneGuide.WidthAnchor, 10f); mercuryLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorMercury"); venusLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorVenus"); earthLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorEarth"); marsLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorMars"); jupiterLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorJupiter"); saturnLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorSaturn"); uranusLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorUranus"); neptuneLeadingToTrailing.SetIdentifier ("leadingTrailingAnchorNeptune"); regularConstraints = new [] { mercuryLeadingToTrailing, venusLeadingToTrailing, earthLeadingToTrailing, marsLeadingToTrailing, saturnLeadingToTrailing, jupiterLeadingToTrailing, uranusLeadingToTrailing, neptuneLeadingToTrailing }; }
void CreateRegularConstraints() { if (regularConstraints?.Length > 0 && sharedConstraints?.Count > 0) { return; } UILayoutGuide leadingMercuryGuide = NewLayoutGuide("leadingMercuryGuide"); UILayoutGuide leadingVenusGuide = NewLayoutGuide("leadingVenusGuide"); UILayoutGuide leadingEarthGuide = NewLayoutGuide("leadingEarthGuide"); UILayoutGuide leadingMarsGuide = NewLayoutGuide("leadingMarsGuide"); UILayoutGuide leadingJupiterGuide = NewLayoutGuide("leadingJupiterGuide"); UILayoutGuide leadingSaturnGuide = NewLayoutGuide("leadingSaturnGuide"); UILayoutGuide leadingUranusGuide = NewLayoutGuide("leadingUranusGuide"); UILayoutGuide leadingNeptuneGuide = NewLayoutGuide("leadingNeptuneGuide"); UILayoutGuide trailingMercuryGuide = NewLayoutGuide("trailingMercuryGuide"); UILayoutGuide trailingVenusGuide = NewLayoutGuide("trailingVenusGuide"); UILayoutGuide trailingEarthGuide = NewLayoutGuide("trailingEarthGuide"); UILayoutGuide trailingMarsGuide = NewLayoutGuide("trailingMarsGuide"); UILayoutGuide trailingJupiterGuide = NewLayoutGuide("trailingJupiterGuide"); UILayoutGuide trailingSaturnGuide = NewLayoutGuide("trailingSaturnGuide"); UILayoutGuide trailingUranusGuide = NewLayoutGuide("trailingUranusGuide"); UILayoutGuide trailingNeptuneGuide = NewLayoutGuide("trailingNeptuneGuide"); IUILayoutSupport topLayoutGuide = TopLayoutGuide; var planetsAndGuides = NSDictionary.FromObjectsAndKeys(new object[] { mercury, venus, earth, mars, jupiter, saturn, uranus, neptune, leadingMercuryGuide, leadingVenusGuide, leadingEarthGuide, leadingMarsGuide, leadingJupiterGuide, leadingSaturnGuide, leadingUranusGuide, leadingNeptuneGuide, trailingMercuryGuide, trailingVenusGuide, trailingEarthGuide, trailingMarsGuide, trailingJupiterGuide, trailingSaturnGuide, trailingUranusGuide, trailingNeptuneGuide, topLayoutGuide }, new object[] { "mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune", "leadingMercuryGuide", "leadingVenusGuide", "leadingEarthGuide", "leadingMarsGuide", "leadingJupiterGuide", "leadingSaturnGuide", "leadingUranusGuide", "leadingNeptuneGuide", "trailingMercuryGuide", "trailingVenusGuide", "trailingEarthGuide", "trailingMarsGuide", "trailingJupiterGuide", "trailingSaturnGuide", "trailingUranusGuide", "trailingNeptuneGuide", "topLayoutGuide" }); var topToBottom = NSLayoutConstraint.FromVisualFormat("V:|[topLayoutGuide]-[leadingMercuryGuide]-" + "[leadingVenusGuide]-[leadingEarthGuide]-[leadingMarsGuide]-" + "[leadingJupiterGuide][leadingSaturnGuide][leadingUranusGuide]-" + "[leadingNeptuneGuide]-20-|", NSLayoutFormatOptions.DirectionLeadingToTrailing, null, planetsAndGuides); sharedConstraints = new List <NSLayoutConstraint> (topToBottom); SetLayoutIdentifierForArray((NSString)"topToBottom", NSArray.FromObjects(topToBottom)); NewHorizontalArray("|[leadingMercuryGuide][mercury][trailingMercuryGuide]|", "hMercury", planetsAndGuides); NewHorizontalArray("|[leadingVenusGuide][venus][trailingVenusGuide]|", "hVenus", planetsAndGuides); NewHorizontalArray("|[leadingEarthGuide][earth][trailingEarthGuide]|", "hEarth", planetsAndGuides); NewHorizontalArray("|[leadingMarsGuide][mars][trailingMarsGuide]|", "hMars", planetsAndGuides); NewHorizontalArray("|[leadingJupiterGuide][jupiter][trailingJupiterGuide]|", "hJupiter", planetsAndGuides); NewHorizontalArray("|[leadingSaturnGuide][saturn][trailingSaturnGuide]|", "hSaturn", planetsAndGuides); NewHorizontalArray("|[leadingUranusGuide][uranus][trailingUranusGuide]|", "hUranus", planetsAndGuides); NewHorizontalArray("|[leadingNeptuneGuide][neptune][trailingNeptuneGuide]|", "hNeptune", planetsAndGuides); sharedConstraints.Add(GuideHeightToPlanet(leadingMercuryGuide, mercury, "guideHeightToMercury")); sharedConstraints.Add(GuideHeightToPlanet(leadingVenusGuide, venus, "guideHeightToVenus")); sharedConstraints.Add(GuideHeightToPlanet(leadingEarthGuide, earth, "guideHeightToEarth")); sharedConstraints.Add(GuideHeightToPlanet(leadingMarsGuide, mars, "guideHeightToMars")); sharedConstraints.Add(GuideHeightToPlanet(leadingJupiterGuide, jupiter, "guideHeightToJupiter")); sharedConstraints.Add(GuideHeightToPlanet(leadingSaturnGuide, saturn, "guideHeightToSaturn")); sharedConstraints.Add(GuideHeightToPlanet(leadingUranusGuide, uranus, "guideHeightToUranus")); sharedConstraints.Add(GuideHeightToPlanet(leadingNeptuneGuide, neptune, "guideHeightToNeptune")); mercuryLeadingToTrailing = leadingMercuryGuide.WidthAnchor.ConstraintEqualToAnchor(trailingMercuryGuide.WidthAnchor, .02f); venusLeadingToTrailing = leadingVenusGuide.WidthAnchor.ConstraintEqualToAnchor(trailingVenusGuide.WidthAnchor, .03f); earthLeadingToTrailing = leadingEarthGuide.WidthAnchor.ConstraintEqualToAnchor(trailingEarthGuide.WidthAnchor, .06f); marsLeadingToTrailing = leadingMarsGuide.WidthAnchor.ConstraintEqualToAnchor(trailingMarsGuide.WidthAnchor, .1f); jupiterLeadingToTrailing = leadingJupiterGuide.WidthAnchor.ConstraintEqualToAnchor(trailingJupiterGuide.WidthAnchor, .2f); saturnLeadingToTrailing = leadingSaturnGuide.WidthAnchor.ConstraintEqualToAnchor(trailingSaturnGuide.WidthAnchor, 1f); uranusLeadingToTrailing = leadingUranusGuide.WidthAnchor.ConstraintEqualToAnchor(trailingUranusGuide.WidthAnchor, 2.7f); neptuneLeadingToTrailing = leadingNeptuneGuide.WidthAnchor.ConstraintEqualToAnchor(trailingNeptuneGuide.WidthAnchor, 10f); mercuryLeadingToTrailing.SetIdentifier("leadingTrailingAnchorMercury"); venusLeadingToTrailing.SetIdentifier("leadingTrailingAnchorVenus"); earthLeadingToTrailing.SetIdentifier("leadingTrailingAnchorEarth"); marsLeadingToTrailing.SetIdentifier("leadingTrailingAnchorMars"); jupiterLeadingToTrailing.SetIdentifier("leadingTrailingAnchorJupiter"); saturnLeadingToTrailing.SetIdentifier("leadingTrailingAnchorSaturn"); uranusLeadingToTrailing.SetIdentifier("leadingTrailingAnchorUranus"); neptuneLeadingToTrailing.SetIdentifier("leadingTrailingAnchorNeptune"); regularConstraints = new [] { mercuryLeadingToTrailing, venusLeadingToTrailing, earthLeadingToTrailing, marsLeadingToTrailing, saturnLeadingToTrailing, jupiterLeadingToTrailing, uranusLeadingToTrailing, neptuneLeadingToTrailing }; }