[英]How to set large titles on Xamarin Forms iOS using Shell
Since Shell doesn't have a Navigationbar, how I can I set large Titles as described here Xamarin Forms iOS Large Title microsoft docs ? Since Shell doesn't have a Navigationbar, how I can I set large Titles as described here Xamarin Forms iOS Large Title microsoft docs ?
If I set:如果我设置:
xmlns:ios="clr-namespace:Xamarin.Forms.PlatformConfiguration.iOSSpecific;assembly=Xamarin.Forms.Core" ios:Page.LargeTitleDisplay="Always" Title="Settings"
on the ContentPage
of an AppShell
app nothing changes...在
AppShell
应用程序的ContentPage
上没有任何变化......
This could be achieved by using Shell Custom Renderers , and then set the Font of the TitleTextAttributes like Font = UIFont.FromName("Courier", 35f)
.这可以通过使用Shell 自定义渲染器来实现,然后设置TitleTextAttributes的字体,如
Font = UIFont.FromName("Courier", 35f)
。
Here's the code sample below for your reference:下面是代码示例供您参考:
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(APPNAME.AppShell), typeof(APPNAME.iOS.Renderers.CustomShellRenderer))]
namespace APPNAME.iOS.Renderers
{
public class CustomShellRenderer : ShellRenderer
{
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
var renderer = base.CreateShellSectionRenderer(shellSection);
if (renderer != null)
{
if (renderer is ShellSectionRenderer shellRenderer)
{
var appearance = new UINavigationBarAppearance();
appearance.ConfigureWithOpaqueBackground();
appearance.BackgroundColor = new UIColor(red: 0.86f, green: 0.24f, blue: 0.00f, alpha: 1.00f);
appearance.TitleTextAttributes = new UIStringAttributes() {
ForegroundColor = UIColor.White,
Font = UIFont.FromName("Courier", 35f)
};
shellRenderer.NavigationBar.Translucent = false;
shellRenderer.NavigationBar.StandardAppearance = appearance;
shellRenderer.NavigationBar.ScrollEdgeAppearance = shellRenderer.NavigationBar.StandardAppearance;
}
}
return renderer;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.