Xamarin iOS 将默认图标颜色更改为在浅色模式下为白色

huangapple go评论89阅读模式
英文:

Xamarin iOS change the default icon color to white in Light Mode

问题

如何在iOS设备的浅色模式下显示深色模式图标?我已经搜索了几个月的这个问题,每篇帖子似乎都陷入了死胡同,或者解决方案根本不起作用。我正在使用Xamarin 17.3和VS 2022进行应用程序开发,同时为Android和iOS开发应用程序。我们有Shell的背景颜色(<Setter Property="Shell.BackgroundColor" Value="#141B4D"),这是一种深蓝色。默认的黑色图标(电池、时间等)在这个背景下显示不清楚(这是公司的颜色,不能更改)。Android似乎自行处理这个问题,我不需要进行任何更改,浅色和深色模式下都会显示浅色图标在深色背景上。但是在iOS的浅色模式下,黑色图标显示但看不见。在深色模式下,浅色图标显示正常。

不久前,我尝试了一个建议,在共享应用程序中告诉它在浅色模式下使用深色模式图标。

<Shell.Resources>
    <ResourceDictionary>
        <Style x:Key="BaseStyle" TargetType="Element">
            <Setter Property="Shell.BackgroundColor" Value="{AppThemeBinding Dark=Black, Light=#141B4D}" />
            <Setter Property="Shell.ForegroundColor" Value="{AppThemeBinding Dark=White, Light=White}" />
        </Style>
    </ResourceDictionary>
</Shell.Resources>

但这并不起作用。因此,我真的需要一些帮助来解决这个问题。如果这不是处理这个问题的正确方式,欢迎提供一个好的替代方案。
谢谢。

英文:

How do I display the dark mode icon while in Light mode on an iOS device? I have been searching this issue for months now and every post seems to come to dead end or the solutions just don't work. Using Xamarin 17.3 & VS 2022 and and developing an app for both Android & iOS. We have the Shell's background color (<Setter Property="Shell.BackgroundColor" Value="141B4D") which is a dark blue. The default, black icons (battery, time & etc.) don't show well with this background (its a company color and can't change it.) Android seems to handle this on its own and I didn't have to make any changes & the light icons show on the dark background in both Light & Dark modes. But on iOS in light mode the black icons display but cannot be seen. In dark mode the light icons show just fine.
Awhile back I tried a suggestion to to tell it, in the shared app, to use the dark mode icons in light mode.

    &lt;Shell.Resources&gt;
    &lt;ResourceDictionary&gt;
        &lt;Style x:Key=&quot;BaseStyle&quot; TargetType=&quot;Element&quot;&gt;
            &lt;Setter Property=&quot;Shell.BackgroundColor&quot; Value=&quot;{AppThemeBinding Dark=Black, Light=#141B4D}&quot; /&gt;
            &lt;Setter Property=&quot;Shell.ForegroundColor&quot; Value=&quot;{AppThemeBinding Dark=White, Light=White}&quot; /&gt;

But this doesn't work. So I really need some help in solving this. And if this is not the proper way to handle this a good alternative is welcomed.
Thanks

答案1

得分: 0

根据您的代码,似乎您只希望状态栏中的文本或图标为白色,如果我理解正确的话。要实现这个简单的方式是在AppDelegate中添加以下代码:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    ...
    UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
    return base.FinishedLaunching(app, options);
}

此外,您还需要在info.plist文件中添加以下键:

<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>

注意:在属性列表编辑器中,它会显示View controller-based status bar appearance

然后,在深蓝色背景下,您也可以看到白色的图标。以下图片是在浅色模式下的效果。

Xamarin iOS 将默认图标颜色更改为在浅色模式下为白色

希望对您有所帮助。

英文:

Based on your code, seems that you just want the text or icon in statusbar to be white if i understand correctly. So a simple way to achieve is to add the following code in AppDelegate:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        ...
        UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.LightContent;
        return base.FinishedLaunching(app, options);
    }

Also, you have to add one key in info.plist

&lt;key&gt;UIViewControllerBasedStatusBarAppearance&lt;/key&gt;
&lt;false/&gt;

Note: in Property List Editor, it will show View controller-based status bar appearance

Then in dark blue background, you can also see white icon. The following picture is in light mode.

Xamarin iOS 将默认图标颜色更改为在浅色模式下为白色

Hope it works for you.

huangapple
  • 本文由 发表于 2023年2月7日 05:13:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75366644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定