O'Reilly logo

Xamarin Blueprints by Michael Williams

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A cleaner code approach to NSLayout

On our previous screen, we built a very simple user interface using NSLayoutContraints.

Would you agree that the code looked quite clunky?

With our AudioPlayerPage, we are going to use a cleaner approach to coding the NSLayoutConstraints. Firstly, create a new folder called Extras, and add a new file called DictionaryViews.cs:

A cleaner code approach to NSLayout

This class is going to inherit the IEnumerable interface in order to create an NSDictionary; part of this interface is we must specify the GetEnumerator function. It will pull this from the NSDictionary; we also have our Add function, which simply adds a new UIView to the dictionary. Then we ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required