<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Aleksei Starkov on Medium]]></title>
        <description><![CDATA[Stories by Aleksei Starkov on Medium]]></description>
        <link>https://medium.com/@alekseistarkov_59313?source=rss-6b0396e040ec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7F_sMy32_wMEcju3tURifQ.png</url>
            <title>Stories by Aleksei Starkov on Medium</title>
            <link>https://medium.com/@alekseistarkov_59313?source=rss-6b0396e040ec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 17:44:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alekseistarkov_59313/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Performance: FFImageLoading.SVG.Forms vs Xamarin.Forms.Image]]></title>
            <link>https://levelup.gitconnected.com/performance-ffimageloading-svg-forms-vs-xamarin-forms-image-cf47801dfbf6?source=rss-6b0396e040ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf47801dfbf6</guid>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[xamarin-android]]></category>
            <category><![CDATA[xamarin-ios]]></category>
            <category><![CDATA[xamarin]]></category>
            <category><![CDATA[svg]]></category>
            <dc:creator><![CDATA[Aleksei Starkov]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 01:19:51 GMT</pubDate>
            <atom:updated>2022-03-22T01:19:51.121Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you use SVG images? In this article, I’m going to compare FFImageLoading.Svg.Forms vs Xamarin.Forms.Image performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Do0iqxgg8-cD4CV.png" /></figure><p>I love the <a href="https://github.com/luberda-molinet/FFImageLoading">FFImageLoading</a> plugin. Because it’s super easy to use, it’s known probably by every Xamarin developer, it has built-in features like transformations and caching. Because of that when it comes to embedded SVG images, an answer might be obvious: <a href="https://github.com/luberda-molinet/FFImageLoading/wiki/SVG-support">FFImageLoading.Svg.Forms</a>. However, is it a good idea to use our lovely plugin for embedded vector graphics? So let’s check it comparing FFImageLoading.Svg.Forms vs Xamarin.Forms.Image performance.</p><h3>Why we need it?</h3><p>There are a lot of things that make a mobile application user unhappy. A problem might be caused by a backend, bugs, poor UI/UX, or …. performance. Unlike backend or UI/UX that might be out of mobile developer control, the performance of a mobile application is our responsibility and something we have to take care of. When it comes to navigation between pages, probably the most annoying problem for a user is page rendering speed. Let’s imagine a user pushing a button to navigate to another page. The last thing which a user expects is unresponsiveness or delay. That is why it’s important to keep performance in mind and follow good practices. However, there is an inconspicuous thing that can involve page rendering speed significantly — images and icons rendering speed.</p><h3>How to measure FFImageLoading.Svg.Forms vs Xamarin.Forms.Image performance?</h3><p>To measure the performance I’m going to add SVG images to a <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/controls/pages">ContentPage</a> to measure the time between page renderer creation and a moment when a content of the page became visible. After the page loading time will be measured for both platforms (iOS and Android) and both approaches (Xamarin.Forms.Image and FFImageLoading.Svg.Forms) it will be easy to see which way is faster.</p><h3>Preparation</h3><p>I’ll use Visual Studio 2019 for Mac as an IDE. I’ll also use two physical devices to make the measurement: <strong>iPhone SE2 (2020)</strong> and <strong>Samsung A5 2017</strong>. The images are also needed. So I got 15 SVG images of road signs from the internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*H-GuxmegELEsKrGs.png" /><figcaption>Images to display</figcaption></figure><h3>Step 1. Creating an application</h3><p>Now let’s create a blank Xamarin.Forms application and add one more page with navigation to it. To show the measured time on the screen some label is needed. Finally, let’s install the <a href="https://www.nuget.org/packages/Xamarin.FFImageLoading.Svg.Forms">FFImageLoading.Svg.Forms</a> plugin and add the image controls to the StackLayout.</p><pre>using Xamarin.Forms;  namespace _2_SVG_XFImage_vs_FFImageLoading <br>{<br>     public partial class App : Application<br>     {<br>         public App()<br>         {<br>             InitializeComponent();<br>             MainPage = new NavigationPage(new MainPage());<br>         }<br>     }<br> }</pre><pre>&lt;ContentPage<br>     x:Class=&quot;_2_SVG_XFImage_vs_FFImageLoading.MainPage&quot;<br>     xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;<br>     xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;&gt;     &lt;Button<br>         Clicked=&quot;OnButtonClicked&quot;<br>         Text=&quot;Navigate to Images Page&quot;<br>         VerticalOptions=&quot;Center&quot; /&gt;<br>&lt;/ContentPage&gt;</pre><pre>using System;<br>using _SVG_XFImage_vs_FFImageLoading;<br>using Xamarin.Forms;namespace _2_SVG_XFImage_vs_FFImageLoading<br>{<br>     public partial class MainPage : ContentPage<br>     {<br>         public MainPage()<br>         {<br>             InitializeComponent();<br>         }         private async void OnButtonClicked(Object sender, EventArgs e)<br>         {<br>             await Navigation.PushAsync(new ImagesPage());<br>         }<br>     }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hOFX81rcxqtF9Twb.png" /><figcaption>Adding Xamarin.FFImageLoading.Svg.Forms plugin to Shared project</figcaption></figure><pre>&lt;ContentPage<br>     x:Class=&quot;_SVG_XFImage_vs_FFImageLoading.ImagesPage&quot;<br>     xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;<br>     xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;<br>     xmlns:ffSvg=&quot;clr-namespace:FFImageLoading.Svg.Forms;assembly=FFImageLoading.Svg.Forms&quot;&gt;<br>     &lt;ContentPage.Resources&gt;<br>         &lt;ResourceDictionary&gt;<br>             &lt;Style TargetType=&quot;ffSvg:SvgCachedImage&quot;&gt;<br>                 &lt;Setter Property=&quot;Aspect&quot; Value=&quot;AspectFit&quot; /&gt;<br>             &lt;/Style&gt;<br>         &lt;/ResourceDictionary&gt;<br>     &lt;/ContentPage.Resources&gt;<br>      &lt;ScrollView&gt;<br>         &lt;StackLayout Spacing=&quot;10&quot;&gt;<br>             &lt;Label<br>                 x:Name=&quot;measuredTimeLabel&quot;<br>                 FontSize=&quot;Large&quot;<br>                 HorizontalOptions=&quot;Center&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://arrowuparrowdownsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://bicyclesroadsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://crossingsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://dangerousbend.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://horsesroadsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://nobicycles.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://noentry.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://payloadsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://roadlayoutsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://roadsignslippery.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://tramroadsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://trucksign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://tunnelroadsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://warningsign.svg&quot; /&gt;<br>             &lt;ffSvg:SvgCachedImage<br>                 Source=&quot;resource://yieldroadsign.svg&quot; /&gt;<br>         &lt;/StackLayout&gt;<br>     &lt;/ScrollView&gt;<br>&lt;/ContentPage&gt;</pre><pre>using System; using Xamarin.Forms;namespace _SVG_XFImage_vs_FFImageLoading<br>{<br>     public partial class ImagesPage : ContentPage<br>     {<br>         public ImagesPage()<br>         {<br>             InitializeComponent();<br>         }         public void SetMeasuredTime(TimeSpan measuredTime)<br>         {<br>             measuredTimeLabel.Text = $&quot;Measured time is {(int)measuredTime.TotalMilliseconds}ms&quot;;<br>         }<br>     }<br>}</pre><h3>Step 2. Adding an ImagePage iOS renderer</h3><p>Now let’s create a custom renderer for the ImagesPage. The overall rendering time will be measured between render creation and a ViewDidAppear call. To achieve that I write a timestamp to the _startTime field and override ViewDidAppear method. Do not forget to register the renderer properly using the <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/introduction#creating-a-custom-renderer-class">ExportRenderer attribute</a>. After the ViewDidAppear method has been overridden it’s time to calculate the time and show it on the display using the SetMeasuredTime method from the previous step.</p><pre>using System;<br>using _2_SVG_XFImage_vs_FFImageLoading.iOS.Renderers;<br>using _SVG_XFImage_vs_FFImageLoading;<br>using Xamarin.Forms;<br>using Xamarin.Forms.Platform.iOS;[assembly: ExportRenderer(typeof(ImagesPage), typeof(ImagesPageRenderer))]<br>namespace _2_SVG_XFImage_vs_FFImageLoading.iOS.Renderers<br>{<br>     public class ImagesPageRenderer : PageRenderer<br>     {<br>         private ImagesPage _imagesPage;<br>         private TimeSpan _startTime;<br>         public ImagesPageRenderer() : base()<br>         {<br>             _startTime = DateTime.Now.TimeOfDay;<br>         }<br>         <br>         protected override void OnElementChanged(VisualElementChangedEventArgs e)<br>         {<br>             base.OnElementChanged(e);<br>             if (e.NewElement is ImagesPage imagesPage)<br>             {<br>                 _imagesPage = imagesPage;<br>             }<br>         }<br>         public override void ViewDidAppear(bool animated)<br>         {<br>             base.ViewDidAppear(animated);<br>             _imagesPage.SetMeasuredTime(DateTime.Now.TimeOfDay - _startTime);<br>         }<br>     }<br>}</pre><h3>Step 3. Adding an ImagePage Android renderer</h3><p>Now let’s create a custom renderer for the ImagesPage. The overall rendering time will be measured between render creation and a ViewDidAppear call. To achieve that I write a timestamp to the _startTime field and override ViewDidAppear method. Do not forget to register the renderer properly using the <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/introduction#creating-a-custom-renderer-class">ExportRenderer attribute</a>. After the ViewDidAppear method has been overridden it’s time to calculate the time and show it on the display using the SetMeasuredTime method from the previous step.</p><pre>using System;<br>using _2_SVG_XFImage_vs_FFImageLoading.iOS.Renderers;<br>using _SVG_XFImage_vs_FFImageLoading;<br>using Xamarin.Forms;<br>using Xamarin.Forms.Platform.iOS;[assembly: ExportRenderer(typeof(ImagesPage), typeof(ImagesPageRenderer))]namespace _2_SVG_XFImage_vs_FFImageLoading.iOS.Renderers<br>{<br>     public class ImagesPageRenderer : PageRenderer<br>     {<br>         private ImagesPage _imagesPage;<br>         private TimeSpan _startTime;         public ImagesPageRenderer() : base()<br>         {<br>             _startTime = DateTime.Now.TimeOfDay;<br>         }         protected override void OnElementChanged(VisualElementChangedEventArgs e)<br>         {<br>             base.OnElementChanged(e);             if (e.NewElement is ImagesPage imagesPage)<br>             {<br>                 _imagesPage = imagesPage;<br>             }<br>         }         public override void ViewDidAppear(bool animated)<br>         {<br>             base.ViewDidAppear(animated);             _imagesPage.SetMeasuredTime(DateTime.Now.TimeOfDay - _startTime);<br>         }<br>     }<br>}</pre><h3>Step 3. Adding an ImagePage Android renderer</h3><p>The general idea of the android renderer is the same: measure the time between render creation and some native API call that is called right after a page has been rendered. However, Android has no special native callback or event indicating that a view did fully appear. After some googling, I found a recommendation to use <em>OnGlobalLayoutListener</em> for that purpose.</p><pre>using System;<br>using _2_SVG_XFImage_vs_FFImageLoading.Droid.Renderers;<br>using _SVG_XFImage_vs_FFImageLoading;<br>using Android.Content;<br>using Xamarin.Forms;<br>using Xamarin.Forms.Platform.Android;<br>using static Android.Views.ViewTreeObserver;[assembly: ExportRenderer(typeof(ImagesPage), typeof(ImagesPageRenderer))]<br>namespace _2_SVG_XFImage_vs_FFImageLoading.Droid.Renderers<br>{<br>     public class ImagesPageRenderer : PageRenderer, IOnGlobalLayoutListener<br>     {<br>         private ImagesPage _imagesPage;<br>         private TimeSpan _startTime;         public ImagesPageRenderer(Context context) : base(context)<br>         {<br>             _startTime = DateTime.Now.TimeOfDay;<br>         }         protected override void OnElementChanged(ElementChangedEventArgs&lt;Page&gt; e)<br>         {<br>             base.OnElementChanged(e);             if (e.NewElement is ImagesPage imagesPage)<br>             {<br>                 _imagesPage = imagesPage;<br>                 ViewTreeObserver.AddOnGlobalLayoutListener(this);<br>             }<br>         }         public void OnGlobalLayout()<br>         {<br>             ViewTreeObserver.RemoveOnGlobalLayoutListener(this);<br>             _imagesPage.SetMeasuredTime(DateTime.Now.TimeOfDay - _startTime);<br>         }<br>     }<br>}</pre><h3>Measurement for the FFImageLoading way</h3><p>Create a “Resource” folder inside of the shared project and add the SVG images to that folder. Don’t forget to set the “EmbeddedResource” value for the “Build action” property of every image resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/0*MeJosNMI_TitSwne.png" /><figcaption>15 images are in the Resources folder</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/0*nnyUdp9u_5EDiyXL.png" /><figcaption>Set EmbeddedResource build action and Resource ID</figcaption></figure><p>Everything is ready for launch. The results I got are on the following screenshots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*ECZfPlElQeAzn-74zIDKxQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-Cr5JemsYm_8CYTZvsAdg.jpeg" /><figcaption>FFImageLoading measurement results. iPhone SE2020 (Left), Samsung A5 2017 (Right)</figcaption></figure><h3>Measurement for the Xamarin built-in way<br>Step 1. Adding SVG images to iOS project</h3><p>Although SVG images are supported by iOS since iOS 13, both the Rider IDE and the Visual Studio IDE still don’t allow adding SVG images for some reason.<br>However, there is a workaround covered by my previous article. <a href="https://levelup.gitconnected.com/how-to-svg-as-an-ios-image-asset-in-xamarin-8bcb9d7f901a">Read it to learn how to add an SVG image asset to iOS project</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/0*eprKL46v44kuCw6B.png" /><figcaption>SVG iOS Assets</figcaption></figure><h3>Step 2. Adding Android vector images</h3><p>The native way to display SVG images on the Android platform is to convert an SVG image to Android VectorDrawable XML. Fortunately, it’s really easy to make this convertation. I usually use <a href="https://svg2vector.com/">https://svg2vector.com</a>. So after the convertation I add XMLs to Resources/drawable folder of the Android project. Remember: a name of an image must be the same for both iOS asset and Android drawable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/365/0*TbukS-PeuDr5UEED.png" /><figcaption>Android drawables</figcaption></figure><h3>Step 3. Modifying the Forms project</h3><p>Since we don’t need SvgCachedImage control anymore and to make the experiment more clear, I remove FFImageLoading.Svg.Forms NuGet from the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*VZvAucMnlJ9Us3el.png" /><figcaption>Uninstalling FFImageLoading NuGet</figcaption></figure><p>Now I need to modify the ImagesPage.xaml as it is shown below.</p><pre>&lt;ContentPage<br>     x:Class=&quot;_SVG_XFImage_vs_FFImageLoading.ImagesPage&quot;<br>     xmlns=&quot;http://xamarin.com/schemas/2014/forms&quot;<br>     xmlns:x=&quot;http://schemas.microsoft.com/winfx/2009/xaml&quot;&gt;<br>     &lt;ContentPage.Resources&gt;<br>         &lt;ResourceDictionary&gt;<br>             &lt;Style TargetType=&quot;Image&quot;&gt;<br>                 &lt;Setter Property=&quot;Aspect&quot; Value=&quot;AspectFit&quot; /&gt;<br>             &lt;/Style&gt;<br>         &lt;/ResourceDictionary&gt;<br>     &lt;/ContentPage.Resources&gt;     &lt;ScrollView&gt;<br>         &lt;StackLayout Spacing=&quot;10&quot;&gt;<br>             &lt;Label<br>                 x:Name=&quot;measuredTimeLabel&quot;<br>                 FontSize=&quot;Large&quot;<br>                 HorizontalOptions=&quot;Center&quot; /&gt;<br>             &lt;Image Source=&quot;arrowuparrowdownsign&quot; /&gt;<br>             &lt;Image Source=&quot;bicyclesroadsign&quot; /&gt;<br>             &lt;Image Source=&quot;crossingsign&quot; /&gt;<br>             &lt;Image Source=&quot;dangerousbend&quot; /&gt;<br>             &lt;Image Source=&quot;horsesroadsign&quot; /&gt;<br>             &lt;Image Source=&quot;nobicycles&quot; /&gt;<br>             &lt;Image Source=&quot;noentry&quot; /&gt;<br>             &lt;Image Source=&quot;payloadsign&quot; /&gt;<br>             &lt;Image Source=&quot;roadlayoutsign&quot; /&gt;<br>             &lt;Image Source=&quot;roadsignslippery&quot; /&gt;<br>             &lt;Image Source=&quot;tramroadsign&quot; /&gt;<br>             &lt;Image Source=&quot;trucksign&quot; /&gt;<br>             &lt;Image Source=&quot;tunnelroadsign&quot; /&gt;<br>             &lt;Image Source=&quot;warningsign&quot; /&gt;<br>             &lt;Image Source=&quot;yieldroadsign&quot; /&gt;<br>         &lt;/StackLayout&gt;<br>     &lt;/ScrollView&gt;<br>&lt;/ContentPage&gt;</pre><h3>Step 4. Measurement</h3><p>Now we a ready to launch the application again and see the results. Side note: I removed a previous version of the application from devices and called “Build-&gt;Clean All” for the entire solution.</p><p>Results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*gDt2o79XePhpt0BFB7WyzA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-x3USqTBJfH7nd_NalzjUg.jpeg" /><figcaption>Xamarin.Forms.Image measurement results. iPhone SE2020 (Left), Samsung A5 2017 (Right)</figcaption></figure><h3>Conclusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/0*tz6QjRhOGQvn5qY9.png" /><figcaption>Comparison result</figcaption></figure><p>As you can see in the case of the iPhone there is almost no difference. However, Xamarin.Forms.Image control approach is more than twice faster when it comes to Android vector drawable images. When I compared those two approaches previously on other devices the result was the same: there was no significant difference on iPhone 8 but Xamarin.Forms.Image approach was twice faster on Google Pixel 5.</p><p>So as you can see although FFImageLoading.Svg.Forms is a great and easy-to-use plugin, when performance matters probably it’s better to not use it for embedded vector graphics.</p><p>Thank you and have a great day 🙂</p><h3>Tools to convert SVG to VactorDrawable XML</h3><p>Android Studio Guide — <a href="https://developer.android.com/studio/write/vector-asset-studio#svg">https://developer.android.com/studio/write/vector-asset-studio#svg</a><br><a href="https://svg2vector.com/">https://svg2vector.com</a><br><a href="https://inloop.github.io/svg2android/">https://inloop.github.io/svg2android/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf47801dfbf6" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/performance-ffimageloading-svg-forms-vs-xamarin-forms-image-cf47801dfbf6">Performance: FFImageLoading.SVG.Forms vs Xamarin.Forms.Image</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To: SVG as an iOS image asset in Xamarin!]]></title>
            <link>https://levelup.gitconnected.com/how-to-svg-as-an-ios-image-asset-in-xamarin-8bcb9d7f901a?source=rss-6b0396e040ec------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bcb9d7f901a</guid>
            <category><![CDATA[xamarin-ios]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[xamarin]]></category>
            <category><![CDATA[visual-studio-for-mac]]></category>
            <category><![CDATA[xamarin-ios-development]]></category>
            <dc:creator><![CDATA[Aleksei Starkov]]></dc:creator>
            <pubDate>Tue, 08 Mar 2022 14:07:17 GMT</pubDate>
            <atom:updated>2022-03-10T09:29:46.340Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I’m going to share the way to use an SVG image as an iOS image asset in Xamarin mobile application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vP1rz4HrqctjQ6NRBNmD7g.png" /></figure><h3>Introduction</h3><p>Every mobile application with a sophisticated user interface contains embedded images and icons. Every mobile application must look great on multiple mobile devices with different screen sizes and pixel densities. Using raster images like JPG or PNG, every single image asset should be cloned and adjusted individually for every possible pixel density before adding to an asset library. Of course, there are multiple free and premium image asset generators, but it’s still a quite annoying process. Furthermore, such a library of raster images might weigh a lot. That is where vector graphics appear.</p><h3>Where is an issue?</h3><p>SVG is a vector image format and SVG probably is the most convenient format for icons and simple logo-like images. SVG images are smaller than PDF vector images and it is XML-based. It means that parameters like path color or margins might be easily modified without any specific software or designing skills. Moreover, SVG is so popular format for vector assets that there are tons of free or paid SVG ready-to-use assets on the internet. Besides, almost every graphic designer is familiar with it. Finally, SVG is officially supported as an iOS image asset since iOS 13.</p><p>Unfortunately, it turned out that for Xamarin developers that native SVG support doesn’t mean getting rid of using 3’rd party plugins for SVG. Why? While for native developers who use Xcode there is no difference between adding SVG asset and adding PDF asset, Xamarin developers still not able to add SVG assets to Xamarin.iOS project. It doesn’t work for both Visual Studio and Rider IDEs.</p><figure><img alt="Visual Studio for Mac error dialog" src="https://cdn-images-1.medium.com/max/1024/1*RRoJZOfFJ0pR9wO7CCk36w.png" /><figcaption>Visual Studio for Mac</figcaption></figure><figure><img alt="Rider error dialog" src="https://cdn-images-1.medium.com/max/1024/1*Ao6aGre9UrqWgtq53-Njzg.png" /><figcaption>Rider</figcaption></figure><p>Well… I can’t say I was shocked, but it was unpleasant to find something that doesn’t work as it should. So I decided to spend some extra time trying to find a workaround and today I want to share with the Xamarin community what I found.</p><h3>Step 1: Add placeholder PDF vector image to an assets catalog</h3><p>This step is needed only to force IDE to create all folders, files, and necessary *.csproj file entries. You also can add required files and *.csproj file entries manually. The result you have to achieve is on the following screenshots:</p><figure><img alt="Placeholder PDF was applied to the image asset" src="https://cdn-images-1.medium.com/max/1024/1*iRvFWZY8DeS7aPBD0t4sYg.png" /><figcaption>Placeholder PDF was applied to the image asset</figcaption></figure><figure><img alt="All needed files and folders were created" src="https://cdn-images-1.medium.com/max/1024/1*KA0HWV0HYmOpSJJ2LAI0aQ.png" /><figcaption>All needed files and folders were created</figcaption></figure><h3>Step 2: Replace *.pdf file with proper *.svg image</h3><p>Go to <em>[your Xamarin iOS project] -&gt; Assets.xcassets -&gt; [name of asset].imageset</em> folder and replace your placeholder <em>*.pdf</em> file with <em>*.svg</em> file.</p><figure><img alt="Image file was replaced" src="https://cdn-images-1.medium.com/max/1024/1*uWssFSBF0OH0yg307OfRaw.png" /><figcaption>Image file was replaced</figcaption></figure><p>Open <em>[your Xamarin iOS project]/Assets.xcassets/[name of asset].imageset/Contents.json</em> and replace the PDF file name value with the name of your SVG file. In my case, it’s named “map.svg”.</p><figure><img alt="The file name value was changed" src="https://cdn-images-1.medium.com/max/1012/1*avizvRcBFsJwoMfiz_P84w.png" /><figcaption>The file name value was changed</figcaption></figure><p>Open <em>[your Xamarin iOS project]/[project name].csproj</em> and edit a path to your asset. In my case I have to replace <em>Assets.xcassets/map.imageset/placeholder.pdf</em> with <em>Assets.xcassets/map.imageset/map.svg</em>.</p><figure><img alt="Editing *.csproj" src="https://cdn-images-1.medium.com/max/1024/1*MD6-fabfqqbCW6qww5zscA.png" /><figcaption>Editing *.csproj</figcaption></figure><h3>Step 3: Use the asset</h3><p>Use the SVG asset image as usual whether you have Xamarin.Forms application or Xamarin native application. I will use Xamarin.Forms.</p><figure><img alt="Works!" src="https://cdn-images-1.medium.com/max/1024/1*AQwfmr8qnFRk9-4e4ZYDbA.png" /><figcaption>Works!</figcaption></figure><p>Enjoy the result 🙂</p><h3>Summary</h3><p>Yes, it’s possible. Yes, it requires some additional actions. But it works and if you want to use embedded SVG images as iOS image asset in Xamarin without dependency on third-party plugins, now you can.</p><p>Thank you and have a great day 🙂</p><h4>References</h4><p>Icons made by <a href="https://www.freepik.com/">Freepik</a> from <a href="https://www.flaticon.com/">www.flaticon.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bcb9d7f901a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-to-svg-as-an-ios-image-asset-in-xamarin-8bcb9d7f901a">How To: SVG as an iOS image asset in Xamarin!</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>