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
:
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 have the static implicit operator which will return the object as an NSDictionary
(this is used so we can directly pass the object as an NSDictionary
to the FromVisualLayout
function):
public class DictionaryViews : IEnumerable { private readonly NSMutableDictionary _nsDictionary; public DictionaryViews() { ...