gpt4 book ai didi

xamarin.forms - 如何更改标题在导航栏中的位置

转载 作者:行者123 更新时间:2023-12-02 06:34:19 24 4
gpt4 key购买 nike

如何以xamarin形式更改导航栏中标题的位置,从默认的左侧位置改为居中或右侧。

最佳答案

You will need a custom render, here's how i have done it in IOS: (the thing is no way to you to get info from tamarin forms for the UIToolbarItem, so you can use the title to get the button u want or hardcode.

(this code, shows moving the 1st button to the left, leaving the other 2 buttons on the right) attached a screenshot

Create a custom PageRenderer to the page type where you want to access,

[assembly: ExportRenderer(typeof(CategoriesPage), typeof(CategoriesPageRenderer))]

and add

bool updatedButtons = false;
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear (animated);

if (!updatedButtons)
MoveButtonToLeft ();
}


protected void MoveButtonToLeft()
{

var infoButton = NavigationController.TopViewController.NavigationItem.RightBarButtonItems[0];
NavigationController.TopViewController.NavigationItem.LeftBarButtonItem = infoButton;

var favButton = NavigationController.TopViewController.NavigationItem.RightBarButtonItems[1];
var musicButton = NavigationController.TopViewController.NavigationItem.RightBarButtonItems[2];
NavigationController.TopViewController.NavigationItem.RightBarButtonItems = new UIBarButtonItem[2] {favButton, musicButton };

updatedButtons = true;
}

关于xamarin.forms - 如何更改标题在导航栏中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40605603/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com