简体   繁体   English

Xamarin表单-iOS上的菜单图标

[英]Xamarin forms - Menu icon on ios

I have this MasterDetailPage . 我有这个MasterDetailPage

On UWP and Android the upper left icon of the menu is showed correctly, but on iOS appears the label "Menu". 在UWP和Android上,菜单的左上图标正确显示,但在iOS上显示标签“菜单”。

I have an image "Hamburger" inside the xcassets , and I would like to use it. 我在xcassets内有一个“汉堡包”图像,我想使用它。

How can I make this works? 我该如何运作?

<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
            xmlns:views="clr-namespace:Menu_TEST.Views"
            x:Class="Menu_TEST.Views.MainPage">

    <MasterDetailPage.Master>
        <views:MenuPage />
    </MasterDetailPage.Master>

    <MasterDetailPage.Detail>
        <NavigationPage>
            <NavigationPage.Icon>
                <OnPlatform x:TypeArguments="FileImageSource">
                    <On Platform="iOS" Value="Hamburger"/>
                </OnPlatform>
            </NavigationPage.Icon>
            <x:Arguments>
                <views:ItemsPage />
            </x:Arguments>
        </NavigationPage>
    </MasterDetailPage.Detail>
</MasterDetailPage>

I have an image "Hamburger" inside the xcassets, and I would like to use it. 我在xcassets中有一个“汉堡包”图像,我想使用它。

If want to get image from xcassets ,you can refer to this discussion .However this maybe can not work here in MasterDetailPage.Master .So suggest that better use the image from Resources folder. 如果要从xcassets获取图像,可以参考此讨论。但是,在MasterDetailPage.Master这可能无法正常工作。因此建议更好地使用Resources文件夹中的图像。

<MasterDetailPage.Master>
   <views:MenuPage />
</MasterDetailPage.Master>

From your code , MenuPage is setted to the MasterDetailPage.Master property. 在您的代码中, MenuPage被设置为MasterDetailPage.Master属性。 If want to set icon to the upper left,you need to set in MenuPage.xaml as follow. 如果要在左上方设置图标,则需要在MenuPage.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"
             x:Class="AppMasterDetail.Views.MenuPage"
             Title="Menu"
             Icon="hamburger.png"> //Here set icon ,image from 'Resources' folder

    <StackLayout VerticalOptions="FillAndExpand">
        <ListView x:Name="ListViewMenu"
                    HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <Grid Padding="10">
                            <Label Text="{Binding Title}" FontSize="20"/>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>
</ContentPage>

If not have this hamburger.png in project, you also can set title like CGPA6.4 said that. 如果项目中没有此hamburger.png ,则还可以设置标题,例如CGPA6.4这样。

<?xml version="1.0" encoding="utf-8" ?>
    <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="AppMasterDetail.Views.MenuPage"
                 Title="☰">  //Here change 'Menu' to '☰'
        ...

 </ContentPage>

Here is a official document with sample , you can refer to. 这是带有样本 的正式文档 ,您可以参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM