Polish - James Montemagno https://staging.montemagno.com/tag/polish/ https://staging.montemagno.com/content/images/2017/08/MonogramIcon_Orange_NoBuffer.png Polish - James Montemagno https://staging.montemagno.com/tag/polish/ Hugo -- gohugo.io Tue, 13 Oct 2026 23:21:57 GMT 60 TintColor & Selected Tab Images in Xamarin.Forms iOS https://staging.montemagno.com/tintcolor-selectedimage-xamarin-forms-ios/ 598df8f2c121b60019bf2ff5 Thu, 28 Jan 2016 17:56:38 GMT If you have been reading the blog recently then you know that I have been all about iOS on Xamarin.Forms. I love it! I can’t help myself. No more storyboards, no more xibs, and I get to use Grids and StackLayouts! Who would have thought that James Montemagno would be blogging more about iOS then Android on MotzCodes! Well the main reason is that while out of the box Xamarin.Forms iOS apps look pretty darn good there are still a lot of small tweaks that can add that extra polish to your app. I blogged a bit ago about back text on the NavigationBar, and today I am switching over to our good friend the TabItem on the TabbedPage for Xamarin.Forms. Icons, text, and a highlight color when you tap on it! What more could you want! Well reading the Apple Design Guidelines… a bit more.

TintColor

That is right! Tint! I like to have a theme for my apps as far as colors and styles and TintColor play a huge role into how your app looks on iOS. iOS has a really great Appearance Class that helps you set defaults throughout your application that you can use to take your icons from this:

to this:

with just this single line of code in the `FinishedLaunching` of your `AppDelegate`:

UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(118,53,235);

Selected TabItem Image

Another way to spice up your user interface is to have a a completely different image on the selected tab. Usually it fills in and inverts the icon in some way. For example we would want our tabs to look like:

So the first thing is to create those selected images and add them to your Resources folder in your iOS project:

Notice I have tab_about.png that is what my ContentPage.Icon property is set to. I have added in the _selected.png too, which is what we will want to use. For this to work the naming is very important as you will see because all we need to do is create a custom renderer in our iOS project to swap out the SelectedImage on the TabBarItems when our TabbedPage shows up:

public class SelectedTabPageRenderer : TabbedRenderer
{
       public override void ViewWillAppear(bool animated)
        {

            if (TabBar?.Items == null)
                return;

            var tabs = Element as TabbedPage;
            if (tabs != null)
            {
                for (int i = 0; i < TabBar.Items.Length; i++)
                {
                    UpdateItem(TabBar.Items[i],  tabs.Children[i].Icon);
                }
            }

            base.ViewWillAppear(animated);
        }

        void UpdateItem(UITabBarItem item, string icon)
        {
            if (item == null)
                return;
            try
            {
                icon = icon.Replace(".png", "_selected.png");
                if(item?.SelectedImage?.AccessibilityIdentifier == icon)
                    return;
                item.SelectedImage = UIImage.FromBundle(icon);
                item.SelectedImage.AccessibilityIdentifier = icon;
            }
            catch(Exception ex)
            {
                Console.WriteLine("Unable to set selected icon: " + ex);
            }

        }
}

That’s it! Super crazy simple to make your tabs look about 100% better! Have fun out there.

Looking for Android? Head over to my blog post outlining how to implement it.

]]>
Changing iOS's Back Button Text in Xamarin.Forms https://staging.montemagno.com/changing-ioss-back-button-text-in-xamarinforms/ 598df8f2c121b60019bf2ff6 Wed, 06 Jan 2016 20:57:22 GMT iOS is a pretty unique platform. Since no device has a physical hardware back button like Android the navigation bar must fully represent a way for users to navigate back or close a modal page. To craft a great experience with Xamarin.Forms I always like to try to follow the platform guidelines as close as possible. In this post I am going to tackle the standard PushAsync of a page onto the Navigation stack. By default Xamarin.Forms will automatically add a back arrow when the page is pushed, and will grab the text from the previous page as the back button’s text. This is sometimes alright if it is the “Home” page, but when you have a long title such as “Session Details” and then push the “Speaker Info” page onto it, it can look really messy:

Xamarin.Forms has a simple method that can be called to adjust what the back button’s text property is. It is a bit hidden and a bit hard to understand how to call it. Since a page has a Title, you may assume that there is a BackButtonTitle that would correlate to what would be display, but you would assume wrong. Diving into the API docs we find Xamarin.Forms.NavigationPage.SetBackButtonTitle Method with the docs saying “Sets the title that appears on the back button for page.”. Looking a bit further into the docs we see that it is actually a static method on the NavigationPage class. You are probably thinking at this point wait… why is it on the NavigationPage when you are setting a property for the page. This is a great question that also puzzled me. So how would you use it? All you have to do is call the static method as the first thing you do in the constructor of any page:

NavigationPage.SetBackButtonTitle(this, "Back");

That’s it! It is actually pretty simple, although a bit tedious since it can’t be set in XAML of any sort. Look how much better that looks now! Beautiful. 

Update! Looks like I spoke too soon about the XAML as my good friend Jason Smith here at Xamarin was quick to correct me:

That’s right simply add:

NavigationPage.BackButtonTitle="Back"

into your Content page’s root!

]]>