Skip to main content
 首页 » 编程设计

c#之IOS 工具栏上的图标颜色保持蓝色 xamarin.forms

2024年01月22日49sxdcgaq8080

我在 Toolbar 上使用了一个 red icon ,但它仍然是默认的蓝色。我怎样才能把它变成红色。 因为最初图标的颜色最初是红色的。 请问我该如何解决。

下面是图片:

这是 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); 
        } 
    } 

请您参考如下方法:

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

UINavigationBar.Appearance.TintColor = UIColor.Red; 

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