Skip to content

Commit 503783e

Browse files
committed
example for center constraints
1 parent b082bbf commit 503783e

File tree

6 files changed

+88
-6
lines changed

6 files changed

+88
-6
lines changed

QuickLayout.Core/QuickLayout.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Compile Include="ViewModels\FullSizeViewModel.cs" />
4646
<Compile Include="ViewModels\SearchViewModel.cs" />
4747
<Compile Include="ViewModels\TipViewModel.cs" />
48+
<Compile Include="ViewModels\ToCenterConstraintsViewModel.cs" />
4849
<Compile Include="ViewModels\UpdateConstraintsViewModel.cs" />
4950
<Compile Include="ViewModels\AdvancedVerticalStackViewModel.cs" />
5051
<Compile Include="ViewModels\DirectionFormViewModel.cs" />

QuickLayout.Core/ViewModels/FirstViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ public class FirstViewModel
2626
public void GoRightToLeft() => ShowViewModel<RightToLeftViewModel>();
2727

2828
public void GoViewWithSafeArea() => ShowViewModel<ViewWithSafeAreaViewModel>();
29+
30+
public void GoCenterConstraints() => ShowViewModel<ToCenterConstraintsViewModel>();
2931
}
3032
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using MvvmCross.Core.ViewModels;
2+
3+
namespace QuickLayout.Core.ViewModels
4+
{
5+
public class ToCenterConstraintsViewModel : MvxViewModel
6+
{
7+
}
8+
}

QuickLayout.Touch/QuickLayout.Touch.csproj

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<Compile Include="Main.cs" />
9191
<Compile Include="AppDelegate.cs" />
9292
<Compile Include="Setup.cs" />
93+
<Compile Include="Views\ToCenterConstraintsView.cs" />
9394
<Compile Include="Views\DetailsView.cs" />
9495
<Compile Include="Views\FirstView.cs" />
9596
<Compile Include="Views\FormGridView.cs" />
@@ -159,11 +160,21 @@
159160
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />
160161
</ItemGroup>
161162
<ItemGroup>
162-
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Contents.json" />
163-
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Default.png" />
164-
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Default%402x.png" />
165-
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Default-568h%402x.png" />
166-
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
163+
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Contents.json">
164+
<Visible>false</Visible>
165+
</ImageAsset>
166+
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Default.png">
167+
<Visible>false</Visible>
168+
</ImageAsset>
169+
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Default%402x.png">
170+
<Visible>false</Visible>
171+
</ImageAsset>
172+
<ImageAsset Include="Assets.xcassets\LaunchImage.launchimage\Default-568h%402x.png">
173+
<Visible>false</Visible>
174+
</ImageAsset>
175+
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json">
176+
<Visible>false</Visible>
177+
</ImageAsset>
167178
</ItemGroup>
168179
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
169180
</Project>

QuickLayout.Touch/Views/FirstView.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace QuickLayout.Touch.Views
1111
[Register("FirstView")]
1212
public class FirstView : MvxViewController
1313
{
14-
private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea;
14+
private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea, _viewCenterConstraints;
1515

1616
public override void ViewDidLoad()
1717
{
@@ -66,6 +66,10 @@ public override void ViewDidLoad()
6666
_viewSafeArea.SetTitle("View with Safe Area", UIControlState.Normal);
6767
Add(_viewSafeArea);
6868

69+
_viewCenterConstraints = new UIButton(UIButtonType.RoundedRect);
70+
_viewCenterConstraints.SetTitle("View Contraining to centers", UIControlState.Normal);
71+
Add(_viewCenterConstraints);
72+
6973
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
7074

7175
var set = this.CreateBindingSet<FirstView, FirstViewModel>();
@@ -80,6 +84,7 @@ public override void ViewDidLoad()
8084
set.Bind(_directionFormView).To("GoDirectionForm");
8185
set.Bind(_rightToLeft).To("GoRightToLeft");
8286
set.Bind(_viewSafeArea).To("GoViewWithSafeArea");
87+
set.Bind(_viewCenterConstraints).To("GoCenterConstraints");
8388
set.Apply();
8489

8590
var constraints = View.VerticalStackPanelConstraints(
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Cirrious.FluentLayouts.Touch;
2+
using Foundation;
3+
using MvvmCross.iOS.Views;
4+
using QuickLayout.Core.ViewModels;
5+
using UIKit;
6+
7+
namespace QuickLayout.Touch.Views
8+
{
9+
[Register("ToCenterConstraintsView")]
10+
public class ToCenterConstraintsView : MvxViewController<ToCenterConstraintsViewModel>
11+
{
12+
public override void ViewDidLoad()
13+
{
14+
15+
UIView firstContainer = new UIView
16+
{
17+
TranslatesAutoresizingMaskIntoConstraints = false,
18+
BackgroundColor = UIColor.Blue
19+
},
20+
21+
secondContainer = new UIView
22+
{
23+
TranslatesAutoresizingMaskIntoConstraints = false,
24+
BackgroundColor = UIColor.Red
25+
},
26+
27+
thirdContainer = new UIView
28+
{
29+
TranslatesAutoresizingMaskIntoConstraints = false,
30+
BackgroundColor = UIColor.Yellow,
31+
Alpha = .5f
32+
};
33+
34+
View.AddSubviews(firstContainer, secondContainer, thirdContainer);
35+
36+
View.AddConstraints(new FluentLayout[]
37+
{
38+
firstContainer.AtTopOf(View),
39+
firstContainer.AtLeftOf(View),
40+
firstContainer.AboveCenterOf(View, 10f),
41+
firstContainer.ToLeftOfCenterOf(View, 10f),
42+
43+
secondContainer.AtBottomOf(View),
44+
secondContainer.AtRightOf(View),
45+
secondContainer.ToRightOfCenterOf(View, 10f),
46+
secondContainer.BelowCenterOf(View, 10f),
47+
48+
thirdContainer.ToRightOfCenterOf(firstContainer),
49+
thirdContainer.ToLeftOfCenterOf(secondContainer),
50+
thirdContainer.AboveCenterOf(secondContainer),
51+
thirdContainer.BelowCenterOf(firstContainer)
52+
});
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)