How to change text color of title on page loaded from "More..." tab

ryan willis 21 Reputation points
2022-05-09T22:01:06.487+00:00

200376-simulator-screen-shot-ipod-touch-7th-generation-20.png

After clicking the "More..." item in the tab bar it then shows a list of pages to choose to navigate to. After selecting one of these pages, it then has the page title at the top along with a back More button to return to the previous list as shown in the screen shot. How could I change the text color of this page title (i.e. the "Inspections" in above screenshot)? That page title is auto-generated and I'm wondering if there's a way to either change its text color or remove it....

Developer technologies | .NET | Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. ryan willis 21 Reputation points
    2022-05-10T15:28:04.427+00:00

    I've figured out how to do it and here is how

    using UIKit;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;
    
    [assembly: Xamarin.Forms.ExportRenderer(typeof(BottomNavigationTabbedPage), typeof(ExtendedTabbedPageRenderer))]
    public class ExtendedTabbedPageRenderer : TabbedRenderer
    {
        string darkBackgroundColor = "#303030"; //This is DarkPageBackgroundColor from the Application Resources page
    
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);
    
            if (e.OldElement == null)
                MoreNavigationController.Delegate = new CustomMoreNavigationControllerDelegate();
        }
    }
    
    internal class CustomMoreNavigationControllerDelegate : UINavigationControllerDelegate
    {
        public override void WillShowViewController(UINavigationController navigationController, UIViewController viewController, bool animated)
        {
            if (Application.Current.UserAppTheme == OSAppTheme.Dark)
            {
                viewController.NavigationController.NavigationBarHidden = false;
    
                if (viewController.NavigationItem.Title == "Inspections")
                {
                    UILabel titleLabel = new UILabel();
                    titleLabel.Text = "Inspections";
                    titleLabel.TextColor = UIColor.White;
    
                    viewController.NavigationItem.TitleView = titleLabel;
                }
                else
                {
                    UILabel titleLabel = new UILabel();
                    titleLabel.Text = "More";
                    titleLabel.TextColor = UIColor.White;
    
                    viewController.NavigationItem.TitleView = titleLabel;
                }
    
                viewController.View.BackgroundColor = UIColor.FromRGB(48, 48, 48);
                viewController.View.TintColor = UIColor.White;
    
                if (viewController.View is UITableView tableView)
                {
                    tableView.SeparatorColor = UIColor.White;
                    foreach (var cell in tableView.VisibleCells)
                    {
                        cell.BackgroundColor = UIColor.FromRGB(48, 48, 48);
                        cell.TextLabel.TextColor = cell.TintColor = UIColor.White;
                    }
                }
            }
            else
            {
                viewController.NavigationController.NavigationBarHidden = false;
    
                if (viewController.NavigationItem.Title == "Inspections")
                {
                    UILabel titleLabel = new UILabel();
                    titleLabel.Text = "Inspections";
                    titleLabel.TextColor = UIColor.Black;
    
                    viewController.NavigationItem.TitleView = titleLabel;
                }
                else
                {
                    UILabel titleLabel = new UILabel();
                    titleLabel.Text = "More";
                    titleLabel.TextColor = UIColor.Black;
    
                    viewController.NavigationItem.TitleView = titleLabel;
                }
    
                viewController.View.BackgroundColor = UIColor.White;
                viewController.View.TintColor = UIColor.Black;
    
                if (viewController.View is UITableView tableView)
                {
                    tableView.SeparatorColor = UIColor.White;
                    foreach (var cell in tableView.VisibleCells)
                    {
                        cell.BackgroundColor = UIColor.White;
                        cell.TextLabel.TextColor = cell.TintColor = UIColor.Black;
                    }
                }
            }
        }
    }
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.