Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cirrious.FluentLayout/AdvancedFluentLayoutExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public static FluentLayout Above(this UIView view, UIView previous, nfloat? marg
view.Bottom().EqualTo().TopOf(previous).Minus(margin.GetValueOrDefault(DefaultMargin));

public static FluentLayout WithSameLeft(this UIView view, UIView previous) => view.Left().EqualTo().LeftOf(previous);


public static FluentLayout WithAspectRatio(this UIView view, nfloat ratio) =>
view.Width().EqualTo().HeightOf(view).WithMultiplier(ratio);

public static FluentLayout WithSameTop(this UIView view, UIView previous) => view.Top().EqualTo().TopOf(previous);

public static FluentLayout WithSameCenterX(this UIView view, UIView previous) => view.CenterX().EqualTo().CenterXOf(previous);
Expand Down
9 changes: 9 additions & 0 deletions QuickLayout.Core/ViewModels/AspectRatioViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MvvmCross.ViewModels;

namespace QuickLayout.Core.ViewModels
{
public class AspectRatioViewModel : MvxViewModel
{

}
}
2 changes: 2 additions & 0 deletions QuickLayout.Core/ViewModels/FirstViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public FirstViewModel(IMvxLogProvider logProvider, IMvxNavigationService navigat
public void GoViewWithSafeArea() => NavigationService.Navigate<ViewWithSafeAreaViewModel>();

public void GoCenterConstraints() => NavigationService.Navigate<ToCenterConstraintsViewModel>();

public void GoViewAspectRatio() => NavigationService.Navigate<AspectRatioViewModel>();
}
}
1 change: 1 addition & 0 deletions QuickLayout.Touch/QuickLayout.Touch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="LinkerPleaseInclude.cs" />
<Compile Include="Main.cs" />
<Compile Include="AppDelegate.cs" />
<Compile Include="Views\AspectRatioView.cs" />
<Compile Include="Views\ToCenterConstraintsView.cs" />
<Compile Include="Views\DetailsView.cs" />
<Compile Include="Views\FirstView.cs" />
Expand Down
56 changes: 56 additions & 0 deletions QuickLayout.Touch/Views/AspectRatioView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using Cirrious.FluentLayouts.Touch;
using MvvmCross.Platforms.Ios.Views;
using QuickLayout.Core.ViewModels;
using UIKit;

namespace QuickLayout.Touch.Views
{
public class AspectRatioView : MvxViewController<AspectRatioViewModel>
{
public override void ViewDidLoad()
{
View.BackgroundColor = UIColor.Black;

var firstView = new UIView()
{
BackgroundColor = UIColor.Red,
Alpha = 0.5f
};
var secondView = new UIView()
{
BackgroundColor = UIColor.Blue,
Alpha = 0.5f
};
var thirdView = new UIView()
{
BackgroundColor = UIColor.Yellow
};

View.AddSubviews(firstView, secondView, thirdView);
View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

const float length = 200f;
const float padding = 32f;

View.AddConstraints(new FluentLayout[]
{
firstView.WithSameCenterX(View),
firstView.WithSameCenterY(View),
secondView.WithSameCenterX(View),
secondView.WithSameCenterY(View),
thirdView.WithSameCenterX(View),
thirdView.WithSameCenterY(View),

firstView.Height().EqualTo(length),
firstView.WithAspectRatio(1f/2f), // height is 2x larger than width

secondView.Width().EqualTo().HeightOf(firstView),
secondView.WithAspectRatio(2f/1f), // width is 2x larger than height

thirdView.Width().EqualTo().WidthOf(firstView).Minus(padding),
thirdView.WithAspectRatio(1f), // width and height are equal (force to be square)
});
}
}
}
7 changes: 6 additions & 1 deletion QuickLayout.Touch/Views/FirstView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace QuickLayout.Touch.Views
[MvxRootPresentation(WrapInNavigationController = true)]
public class FirstView : MvxViewController
{
private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea, _viewCenterConstraints;
private UIButton _viewForm, _viewFormGrid, _viewDetails, _viewSearch, _viewTip, _viewUpdateConstaints, _viewAdvancedVerticalStack, _fullSize, _directionFormView, _rightToLeft, _viewSafeArea, _viewCenterConstraints, _viewAspectRatio;

public override void ViewDidLoad()
{
Expand Down Expand Up @@ -71,6 +71,10 @@ public override void ViewDidLoad()
_viewCenterConstraints = new UIButton(UIButtonType.RoundedRect);
_viewCenterConstraints.SetTitle("View Contraining to centers", UIControlState.Normal);
Add(_viewCenterConstraints);

_viewAspectRatio = new UIButton(UIButtonType.RoundedRect);
_viewAspectRatio.SetTitle("Aspect Ratio", UIControlState.Normal);
Add(_viewAspectRatio);

View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();

Expand All @@ -87,6 +91,7 @@ public override void ViewDidLoad()
set.Bind(_rightToLeft).To("GoRightToLeft");
set.Bind(_viewSafeArea).To("GoViewWithSafeArea");
set.Bind(_viewCenterConstraints).To("GoCenterConstraints");
set.Bind(_viewAspectRatio).To("GoViewAspectRatio");
set.Apply();

var constraints = View.VerticalStackPanelConstraints(
Expand Down