diff --git a/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs b/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs index 1022d80..5981529 100644 --- a/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs +++ b/Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs @@ -110,7 +110,19 @@ public static FluentLayout ToTopMargin(this UIView view, UIView previous) => view.Top().EqualTo().TopMarginOf(previous); public static FluentLayout ToBottomMargin(this UIView view, UIView previous) => - view.Bottom().EqualTo().BottomMarginOf(previous); + view.Bottom().EqualTo().BottomMarginOf(previous); + + public static FluentLayout ToLeftOfCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Right().EqualTo().CenterXOf(previous).Minus(margin.GetValueOrDefault(0)); + + public static FluentLayout ToRightOfCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Left().EqualTo().CenterXOf(previous).Plus(margin.GetValueOrDefault(0)); + + public static FluentLayout AboveCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Bottom().EqualTo().CenterYOf(previous).Minus(margin.GetValueOrDefault(0)); + + public static FluentLayout BelowCenterOf(this UIView view, UIView previous, nfloat? margin = null) => + view.Top().EqualTo().CenterYOf(previous).Plus(margin.GetValueOrDefault(0)); public static IEnumerable FullWidthOf(this UIView view, UIView parent, nfloat? margin = null) { diff --git a/QuickLayout.Core/QuickLayout.Core.csproj b/QuickLayout.Core/QuickLayout.Core.csproj index 3de6c21..8ef635e 100644 --- a/QuickLayout.Core/QuickLayout.Core.csproj +++ b/QuickLayout.Core/QuickLayout.Core.csproj @@ -45,6 +45,7 @@ + diff --git a/QuickLayout.Core/ViewModels/FirstViewModel.cs b/QuickLayout.Core/ViewModels/FirstViewModel.cs index 59d38af..47998aa 100644 --- a/QuickLayout.Core/ViewModels/FirstViewModel.cs +++ b/QuickLayout.Core/ViewModels/FirstViewModel.cs @@ -26,5 +26,7 @@ public class FirstViewModel public void GoRightToLeft() => ShowViewModel(); public void GoViewWithSafeArea() => ShowViewModel(); + + public void GoCenterConstraints() => ShowViewModel(); } } \ No newline at end of file diff --git a/QuickLayout.Core/ViewModels/ToCenterConstraintsViewModel.cs b/QuickLayout.Core/ViewModels/ToCenterConstraintsViewModel.cs new file mode 100644 index 0000000..79b5df9 --- /dev/null +++ b/QuickLayout.Core/ViewModels/ToCenterConstraintsViewModel.cs @@ -0,0 +1,8 @@ +using MvvmCross.Core.ViewModels; + +namespace QuickLayout.Core.ViewModels +{ + public class ToCenterConstraintsViewModel : MvxViewModel + { + } +} diff --git a/QuickLayout.Touch/QuickLayout.Touch.csproj b/QuickLayout.Touch/QuickLayout.Touch.csproj index 9dd442f..fda8ceb 100644 --- a/QuickLayout.Touch/QuickLayout.Touch.csproj +++ b/QuickLayout.Touch/QuickLayout.Touch.csproj @@ -90,6 +90,7 @@ + @@ -159,11 +160,21 @@ - - - - - + + false + + + false + + + false + + + false + + + false + \ No newline at end of file diff --git a/QuickLayout.Touch/Views/FirstView.cs b/QuickLayout.Touch/Views/FirstView.cs index c8ff226..fe7175e 100644 --- a/QuickLayout.Touch/Views/FirstView.cs +++ b/QuickLayout.Touch/Views/FirstView.cs @@ -11,7 +11,7 @@ namespace QuickLayout.Touch.Views [Register("FirstView")] public class FirstView : MvxViewController { - private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea; + private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea, _viewCenterConstraints; public override void ViewDidLoad() { @@ -66,6 +66,10 @@ public override void ViewDidLoad() _viewSafeArea.SetTitle("View with Safe Area", UIControlState.Normal); Add(_viewSafeArea); + _viewCenterConstraints = new UIButton(UIButtonType.RoundedRect); + _viewCenterConstraints.SetTitle("View Contraining to centers", UIControlState.Normal); + Add(_viewCenterConstraints); + View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints(); var set = this.CreateBindingSet(); @@ -80,6 +84,7 @@ public override void ViewDidLoad() set.Bind(_directionFormView).To("GoDirectionForm"); set.Bind(_rightToLeft).To("GoRightToLeft"); set.Bind(_viewSafeArea).To("GoViewWithSafeArea"); + set.Bind(_viewCenterConstraints).To("GoCenterConstraints"); set.Apply(); var constraints = View.VerticalStackPanelConstraints( diff --git a/QuickLayout.Touch/Views/ToCenterConstraintsView.cs b/QuickLayout.Touch/Views/ToCenterConstraintsView.cs new file mode 100644 index 0000000..c98bd14 --- /dev/null +++ b/QuickLayout.Touch/Views/ToCenterConstraintsView.cs @@ -0,0 +1,55 @@ +using Cirrious.FluentLayouts.Touch; +using Foundation; +using MvvmCross.iOS.Views; +using QuickLayout.Core.ViewModels; +using UIKit; + +namespace QuickLayout.Touch.Views +{ + [Register("ToCenterConstraintsView")] + public class ToCenterConstraintsView : MvxViewController + { + public override void ViewDidLoad() + { + + UIView firstContainer = new UIView + { + TranslatesAutoresizingMaskIntoConstraints = false, + BackgroundColor = UIColor.Blue + }, + + secondContainer = new UIView + { + TranslatesAutoresizingMaskIntoConstraints = false, + BackgroundColor = UIColor.Red + }, + + thirdContainer = new UIView + { + TranslatesAutoresizingMaskIntoConstraints = false, + BackgroundColor = UIColor.Yellow, + Alpha = .5f + }; + + View.AddSubviews(firstContainer, secondContainer, thirdContainer); + + View.AddConstraints(new FluentLayout[] + { + firstContainer.AtTopOf(View), + firstContainer.AtLeftOf(View), + firstContainer.AboveCenterOf(View, 10f), + firstContainer.ToLeftOfCenterOf(View, 10f), + + secondContainer.AtBottomOf(View), + secondContainer.AtRightOf(View), + secondContainer.ToRightOfCenterOf(View, 10f), + secondContainer.BelowCenterOf(View, 10f), + + thirdContainer.ToRightOfCenterOf(firstContainer), + thirdContainer.ToLeftOfCenterOf(secondContainer), + thirdContainer.AboveCenterOf(secondContainer), + thirdContainer.BelowCenterOf(firstContainer) + }); + } + } +} \ No newline at end of file