NSLayoutContraints

Let's have a closer look at where we are initializing our UI elements. The TranslatesAutoresizingMaskIntoConstraints property is used to determine whether we are going to use NSLayoutConstraints to build our user interface. When we set it to false, it means we have to implement the layout constraints for this element.

Now we want to build the user interface using layout constraints. Let's add the following after the elements are added to mainView:

View.AddConstraints (NSLayoutConstraint.FromVisualFormat("V:|[mainView]|", NSLayoutFormatOptions.DirectionLeftToRight, null, new NSDictionary("mainView", mainView))); View.AddConstraints (NSLayoutConstraint.FromVisualFormat("H:|[mainView]|", NSLayoutFormatOptions.AlignAllTop, null, new ...

Get Xamarin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.