Terse, readable and safe auto-layout F# DSL for Xamarin iOS.
Write your constraints like this:
mainView.AddConstraints(
[ Mirror(happyView, Top, mainView)
Relate(happyView, Left, Equal, mainView, Left, Times(0.8f), AddZero)
Relate(happyView, Right, Equal, mainView, Right, Times(0.5f), Add(10.0f))
Set(happyView, Bottom, Equal, 250.0f) ])
Or this:
// Use the HappyLayout module function edgeConstraints, to create the 4 constraints I need.
mainView.AddConstraints(Hal.edgeConstraints happyView mainView)
There are three constraint types:
Relate fully expresses a constraint relationship between the properties of two views.
Mirror specifies that a view property should mirror the value of the same property on the second view. You could specify this with Relate
, but Mirror
is shorter and clearly expresses your intent.
Set directly specifies the value of a property on the view.
Grab HappyAutoLayout.fs and put it in your F# iOS project.
HAL could be used from C# too. Add an F# assembly project and this file and build away. I might try it too one day, or you could just join us in F# land. It's so warm and fuzzy here.
HappyAutoLayout is licensed under MIT.
HappyAutoLayout is at 0.1. It is a tiny bit of code, so don't let that worry you.