【问题标题】:Icon color remains blue on IOS toolbar xamarin.formsIOS 工具栏 xamarin.forms 上的图标颜色保持蓝色
【发布时间】:2017-08-18 08:38:04
【问题描述】:

我在 Toolbar 上使用了 红色图标,但它仍然是默认的蓝色。我怎样才能将其更改为红色。 因为最初图标的颜色最初是红色。 请问我该如何解决这个问题。

图片如下:

这是 Xaml 代码:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    Icon ="nav_icon.png"    Title="Ea "

    x:Class="EAMobileDirectory.MasterPage">

    <StackLayout>
        <Image   Source="featured_newline_1.png"  Margin="0,1,0,0"/>
        <ListView x:Name="listView"   Margin="0,10,0,0" VerticalOptions="FillAndExpand" SeparatorVisibility="None">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ImageCell Text="{Binding Title}" ImageSource="{Binding IconSource}" />
                    </DataTemplate>
                </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>

我还根据@Steven 更改了我的 AppDelegate.cs 文件,下面是我更改的代码:

[Register("AppDelegate")]
    public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
    {
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();

            LoadApplication(new App());
            UIToolbar.Appearance.TintColor = UIColor.Red;
            UIToolbar.Appearance.BarTintColor = UIColor.Green;

            return base.FinishedLaunching(app, options);
        }
    }

【问题讨论】:

    标签: c# xaml xamarin.forms


    【解决方案1】:

    这是由于 TintColor 属性接管了 iOS。它使您能够以您想要的每种颜色提供图像,并且使用TintColor 您可以将它们着色为任何颜色。要更改此设置,请尝试在您的 AppDelegate.cs 中添加此行:

    UINavigationBar.Appearance.TintColor = UIColor.Red;
    

    这将为应用程序中的每个 UINavigationBar 设置图标样式。

    【讨论】:

    • 图标没有改变,但它是具有标题的工具栏,因为当我在 xaml 中添加 时,另一层会添加到可见的那个之上我不想要。还有其他方法吗?
    • 图标是featured_newline_1.png变成蓝色还是nav_icon.png?如果是最后一个,您需要将我示例中的 UIToolbar 更改为 UINavigationBar。
    • 这是nav_icon.png改变颜色,看看我的帖子,我重新编辑了它
    • 尝试将UIToolbar 更改为UINavigationBar。
    • 它就像魅力一样,更新你的答案,我投票感谢人。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    相关资源
    最近更新 更多