This is part 2 of my journey to migrate a Xamarin.Android app to Xamarin.iOS. Let me say that I’m really feeling the impostor syndrome right now because I have a lot to learn to embrace iOS UI programmatic development. But ultimately this will be a new arrow in my quiver. This makes me proud.
Lets improve our skills, shall we?
In oder to stay as close as possible as the android implementation of building the UI dynamically, I needed to replicate AsyncTask.
Cross platform features
Not specifically tied to iOS, these libraries are useful to write the code once.
Because System.Drawing.Bitmap is not available on iOS (neither on Android), I will start using the generic
Image<TPixel> class from ImageSharp
Embracing programmatic Auto Layout
Ok. Let me say that I’ve had a hard time figuring out auto layout until I found this amazing tutorial on YouTube.
I followed it and everything made sense suddenly. I’ve created the Xamarin.iOS c# version of the code. You can find it here.
So the general idea would be to not use a ‘GridView like’ UI Component but stick with constrained UIStackviews or only working with constrained controls.
I’ve find this (now archived) great source of information about programmatic layout with Xamarin.iOS.
Solving constraint issues
This web app has been very helpfull
Copy/paste the constraints listed in the application output and examine the result.
for instance in my case I had the following:
Can you spot the problem? In fact The SfCircular gauge control was simultaneously given both leading and trailing anchors (which basically is like giving a width) plus an explicit width. The autolayout system has to choose. It is better if this is you that is making the wise choice.
In my case I removed the width constraint because I want the control to adjust correctly on various screen sizes.
I’ve Found an online tool that generates c# code (but also Swift/ObjectiveC) from an hex value.
Text Styles & fonts
On Android, I’m using text styles in AXML files.
On iOS, I will set fonts and text styles by code. The iOS default font sizes are available here.
Read this stack overflow answer for a comparison with Android activities
To mimic the RadioGroup available on Android I’ll use the XPlugins.iOS.BEMCheckBox library.
I had an issue that is now resolved, but this led me to some interesting resources about native to managed references.
I have experienced some challenges but stack overflow was the ultimate source of information to get answers.
I learned a lot using UISyackViews which are very powerful and pretty close to LinearLAyouts on Android.
Targeting older phones
32-bit ARM (iOS 9 on iPhone 4s)
Potential AOT compiler issues.
is not supported before iOS 11.
But there is a magic trick to use.
This is a tough subject especially because I needed to have camera and microphone support. But as far as I know this is still unsupported today outside of Safari on iOS 12.4.6 (iPhone 6) and up.
But outside of this WebRTC context, for which I’m trying to Launch Safari directly mixed with DeepLinking, I’m using WKWebView.
Stay tuned for more.