我目前正在学习 Xamarin Forms,并从重新创建我之前为 iOS 开发的应用程序开始。我一直在尝试格式化导航栏(我认为它在表单中称为工具栏),甚至不知道我想要做什么可能。
This took me >5 minutes to knock together in xcode
This is currently what my xamarin project looks like
首先,由于某种原因,我的栏按钮被正确分组,我看过 2014 年的一些旧帖子,说这是不可能的。他们改变了吗?我知道 Xamarin 自 2014 年以来已经发生了很大变化,我找不到最近被问过的问题(也许这是不可能的??)。
其次,我的 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 栏按钮显示在左/右而不是右/右......以及如何让内容页面的背景颜色显示在导航下方/工具栏?
谢谢
最佳答案
实现透明度:
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 之前在 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/
关于ios - Xamarin Forms 工具栏/导航栏格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48648985/