Xamarin表单工具栏/导航栏格式

时间:2018-02-06 17:46:15

标签: ios xamarin xamarin.forms toolbar

我目前正在学习Xamarin Forms,我首先要重新创建我之前为iOS开发的pp。我一直在尝试格式化导航栏(我认为它在表单中称为工具栏),甚至不知道我想做什么。

This took me >5 minutes to knock together in xcode

This is currently what my xamarin project looks like

首先我的酒吧按钮由于某种原因被分组正确,我已经看到2014年的一些旧帖子,这是不可能的。他们改变了吗?我知道Xamarin自2014年以来已经改变了ALOT并且我最近无法找到问题(也许这是不可能的)。

其次,我在iOS中的页面颜色在导航栏下可见。它不在Xamarin中,我使用以下代码设置背景颜色:

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    x:Class="NavigationDemo.MenuPage"
    BackgroundColor="Fuchsia"
    Title = "Navigation Bar">

当然这应该延伸到后面?

因此,对于Xamarin新手,如何设置它以使iOS栏按钮显示为左/右而不是右/右....如何让我的内容页面的背景颜色显示在导航下/工具栏?

由于

1 个答案:

答案 0 :(得分:3)

启用透明度

var navPage = new NavigationPage(new MyContentPage());

switch (Device.RuntimePlatform)
{
    case Device.iOS:
        navPage.On<Xamarin.Forms.PlatformConfiguration.iOS>()
            .EnableTranslucentNavigationBar();
        break;
}

我还没有在不是导航页面的页面上对其进行测试,但我认为它应该可行。您可以尝试使用var myPage = new MyContentPage();

更改导航栏中文字/图标的颜色

AppDelegate.cs中,创建一个名为 InitNavbarAndTabBarAppearance()的方法,并在初始化Xamarin.Forms之前在FinishedLaunching()方法中调用它:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    ...
    InitNavBarAndTabBarAppearance();

    global::Xamarin.Forms.Forms.Init();
    ...
}

InitNavbarAndTabBarAppearance()

private void InitNavBarAndTabBarAppearance()
{
    // Color of the navigation bar title:
    UINavigationBar.Appearance.SetTitleTextAttributes(
        new UITextAttributes()
        {
            TextColor = UIColor.Black,
        });

    // Color of the navigation bar buttons/toolbar items:
    UINavigationBar.Appearance.TintColor = UIColor.FromRGB(0, 122, 255);

    // Color of the selected tab icon & text:
    UITabBarItem.Appearance.SetTitleTextAttributes(
        new UITextAttributes()
        {
            TextColor = UIColor.FromRGB(0, 122, 255)
        }, 
        UIControlState.Selected);

    // Color of the unselected tab icon & text:
    UITabBarItem.Appearance.SetTitleTextAttributes(
        new UITextAttributes()
        {
            TextColor = UIColor.FromRGB(146, 146, 146)
        }, 
        UIControlState.Normal);
}

左侧工具栏

要在导航栏的左侧放置图标,您需要自定义渲染器。见这里:https://timeyoutake.it/2016/01/02/creating-a-left-toolbaritem-in-xamarin-forms/

相关问题