I have been looking around for a while, and I cannot figure out how to check whether the user has an iPad or an iPhone?
I am using Xamarin.Forms, and I have no need to check whether the Android device is a tablet or phone as the issue does not resolve around Android.
Code which I have found that could be helpful:
var idiom = UIKit.UIDevice.CurrentDevice.UserInterfaceIdiom;
Thanks for your time!
You can check this by using the Device Class in Xamarin.Forms
if (Device.Idiom == TargetIdiom.Tablet)
{
// iPad
}
if (Device.Idiom == TargetIdiom.Phone)
{
// iPhone
}
This is a multi-platform solution that works for Android, iOS and Windows Phone.
If you need to make differences in XAML files you can use the OnIdiom tag like this:
<StackLayout>
<StackLayout.Padding>
<OnIdiom x:TypeArguments="Thickness">
<OnIdiom.Phone>
10
</OnIdiom.Phone>
<OnIdiom.Tablet>
20
</OnIdiom.Tablet>
</OnIdiom>
</StackLayout.Padding>
</StackLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With