Bug 58373 - Can't independently set iOS NavigationBar's text, tint, and status bar style.
Summary: Can't independently set iOS NavigationBar's text, tint, and status bar style.
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.3.5
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
: 58374 ()
Depends on:
Blocks:
 
Reported: 2017-07-25 15:33 UTC by Christopher Boyd
Modified: 2017-08-03 13:32 UTC (History)
5 users (show)

Tags: statusbar, ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 58373 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Christopher Boyd 2017-07-25 15:33:24 UTC
# Steps to reproduce
Attempt to follow iOS-specific solutions by manually setting everything in AppDelegate's FinishedLaunching() as described on http://motzcod.es/post/110755300272/ios-tip-change-status-bar-icon-text-colors

I'd like to set NavigationBar's text color to white and the tint color to orange, so that buttons are a different color than the text.
This seems like standard behavior on both Android and iOS, so I don't know why it's difficult with Xamarin.Forms.

If I set the `BarTextColor = Color.White` for the NavigationPage, then they all get set to white (along with the status bar text).

# Expected behavior
Should be able to change status bar style with
```
            UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
```

# Actual behavior
This doesn't work because it gets overridden with the default NavigationRenderer:
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs#L609

There's no way to disable the override, since setting StatusBarTextColorMode.DoNotAdjust will result in the "Default" style with black text.

# Supplemental info (logs, images, videos)


# Test environment (full version information)
Comment 1 Christopher Boyd 2017-07-25 15:46:46 UTC
To clarify, by using AppDelegate and not setting any parameters on the NavigationPage, I'm able to style both the text and tint separately:

            UINavigationBar.Appearance.TintColor = accent;
            UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes
            {
                ForegroundColor = UIColor.White
            };

Setting the BarTextColor property on the NavigationPage, however, will override both of these values.

Similarly, NOT setting the BarTextColor will result in the status bar style getting overridden with UIStatusBarStyle.Default.

Perhaps the L609 ought to be changed from:
if (statusBarColorMode == StatusBarTextColorMode.DoNotAdjust || barTextColor.Luminosity <= 0.5)

To:
if (statusBarColorMode == StatusBarTextColorMode.DoNotAdjust || NavigationBar.TintColor.Luminosity <= 0.5)

Or, possibly, it should be refactored into UpdateBarBackgroundColor() to only use black text on light backgrounds.  (And white text on darker backgrounds.)
Comment 2 Christopher Boyd 2017-07-25 15:49:03 UTC
Sorry for the additional comments... Last idea:

Or maybe, rather than a StatusBarTextColorMode.DoNotAdjust (which doesn't work as the name implies... since it actually DOES still adjust it back to the default), we should just be able to set the value with a platform-specific Black or White.
Comment 3 Christopher Boyd 2017-07-25 15:55:06 UTC
*** Bug 58374 has been marked as a duplicate of this bug. ***
Comment 4 david 2017-08-01 07:17:56 UTC
TintColor.Luminosity <= 0.5 is arbitrary and extremely unhelpful. It basically makes it impossible to have many (valid and visually appealing) schemes in a Xamarin.Forms app. Please remove it and create customisation points instead that allow us to properly set both the font colour and the title bar colour independently of each other.
Comment 5 Christopher Boyd 2017-08-03 13:32:04 UTC
Just to clarify:
You can already set the Title Bar Color and Font Color separately.
Although the Font Color sets both the "Tint" color of buttons (and the back navigation) AND the title text.  (Note: By default the title text is black and "Tint" color is blue on a white navigation bar.)

The status bar text, however, only lets you change between black and white.

From this perspective, the use of "Luminosity" isn't necessarily a bad decision, as it will attempt to go close to whatever text color you use.

I do agree that it might be best to let the user choose, which they could do by having "StatusBarTextColorMode.DoNotAdjust" simply not mess with changes (currently it forces the "default" of black).
In which case you ought to be able to make adjustments in the AppDelegate.