Forum Xamarin.Forms

Is there a way to style the native iOS map like google maps? (xamarin.forms)

I need to colorize the native iOS map with a dark style. But I'm not sure if this is possible. Mb somebody did it before??

Best Answer

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    Accepted Answer

    Which map nuget package do you used?

    If you use Xamarin.Forms.Maps, it does not have Night Mode. But you can create a custom renderer for Map in iOS. (To have it in light mode would be UIUserInterfaceStyle.Light)

    using App52;
    using App52.iOS;
    using Foundation;
    using MapKit;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UIKit;
    using Xamarin.Forms;
    using Xamarin.Forms.Maps;
    using Xamarin.Forms.Maps.iOS;
    using Xamarin.Forms.Platform.iOS;
    
    [assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
    namespace App52.iOS
    {
        public class CustomMapRenderer : MapRenderer
        {
    
            protected override void OnElementChanged(ElementChangedEventArgs<View> e)
            {
                base.OnElementChanged(e);
                var nativeMap = Control as MKMapView;
                nativeMap.OverrideUserInterfaceStyle= UIUserInterfaceStyle.Dark;
    
    
    
            }
    
        }
    }
    
    

    I create CustomMap in PCL.

     public class CustomMap : Map
        {
    
        }
    

    Then use it in the Contentpage.

     <app52:CustomMap></app52:CustomMap>
    

    Here is running screenshot.

    If you use Xamarin.Essentials: Map to open external map. We cannot find a way to set it.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai
    Accepted Answer

    Which map nuget package do you used?

    If you use Xamarin.Forms.Maps, it does not have Night Mode. But you can create a custom renderer for Map in iOS. (To have it in light mode would be UIUserInterfaceStyle.Light)

    using App52;
    using App52.iOS;
    using Foundation;
    using MapKit;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UIKit;
    using Xamarin.Forms;
    using Xamarin.Forms.Maps;
    using Xamarin.Forms.Maps.iOS;
    using Xamarin.Forms.Platform.iOS;
    
    [assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
    namespace App52.iOS
    {
        public class CustomMapRenderer : MapRenderer
        {
    
            protected override void OnElementChanged(ElementChangedEventArgs<View> e)
            {
                base.OnElementChanged(e);
                var nativeMap = Control as MKMapView;
                nativeMap.OverrideUserInterfaceStyle= UIUserInterfaceStyle.Dark;
    
    
    
            }
    
        }
    }
    
    

    I create CustomMap in PCL.

     public class CustomMap : Map
        {
    
        }
    

    Then use it in the Contentpage.

     <app52:CustomMap></app52:CustomMap>
    

    Here is running screenshot.

    If you use Xamarin.Essentials: Map to open external map. We cannot find a way to set it.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • DeathgarDeathgar Member ✭✭

    @LeonLu, thank u so much C:

Sign In or Register to comment.