Xamarin.iOS Auto Layout in Xamarin.iOS Adding Constraints with Masonry


Masonry is a library for objective-c but xamarin have created a binding for it and created it as a nuget package https://www.nuget.org/packages/Masonry/.

Nuget install

Install-Package Masonry

This centers a button 100 points below the centre point of the containing view and sets a width between 200 and 400 points

this.loginBtn.MakeConstraints(make =>
    make.Width.GreaterThanOrEqualTo(new NSNumber(200));
    make.Width.LessThanOrEqualTo(new NSNumber(400));
    make.Center.EqualTo(this.View).CenterOffset(new CGPoint(0, 100));

This sets a scaled image 100 points above the centre point of the containing view then sets the width to the width of the containing view with a muliplier of 0.5 which means 50% of the width. It then sets the height to the width multiplied by the aspect ratio which causes the image to scale but maintain its correct aspect ratio

this.logo.MakeConstraints(make =>
    make.Center.EqualTo(this.View).CenterOffset(new CGPoint(0, -100));