iOSのステータスバーの文字を白くする【Xamarin.Forms(Prism)】
iOSのステータスバーの文字を白くする
Xamrin.FormsでPrism使ってるときにiOSアプリのステータスバーの文字が白くならなかったので試行錯誤した
一応できたけどこういうもんなの?ってモヤモヤが残る。
もっといい方法ありそう。
できたパターン①
.iOSプロジェクトのinfo.plistに
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
起動時のスプラッシュでも変更する場合は以下も
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
PCLでNavigationPageを継承し、コンストラクタで設定する
// usingとかnamespace省略
public class CustomNavigationPage : NavigationPage
{
public CustomNavigationPage() : base()
{
// ナビゲーションバー、ステータスバーの背景色
BarBackgroundColor = Color.Blue;
// ナビゲーションバー、ステータスバーの文字色(ステータスバーは白か黒になる)
BarTextColor = Color.White;
}
}
App.xaml.csでコンテナに登録するNavigationPageをCustomNavigationPageに差し替える
nameはNavigationPageにしておくと差し替えの影響が少ないはず
protected override async void OnInitialized()
{
InitializeComponent();
await NavigationService.NavigateAsync("NavigationPage/MainPage");
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
//containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<CustomNavigationPage>("NavigationPage");
containerRegistry.RegisterForNavigation<MainPage>();
}
できたパターン②
info.plistは①と同様
App.xaml.csでNavigationAsyncしたあとにNavigationPageを取り出してプロパティ変更
protected override async void OnInitialized()
{
InitializeComponent();
await NavigationService.NavigateAsync("NavigationPage/MainPage");
var naviPage = (NavigationPage)MainPage;
naviPage.BarBackgroundColor = Color.Green;
naviPage.BarTextColor = Color.White;
}
Prismを使わないXamarin.FormsだとMainPage
プロパティに最初のページを設定していた気がするので取り出してみたらいけた。
が、どう考えても①の方が安全
ダメだったパターン
info.plistまでは同様
iOSプロジェクトのAppDelegate.csに追加
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App(new iOSInitializer()));
UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false); // ← これ
return base.FinishedLaunching(app, options);
}
結構紹介されているパターンだがステータスバーの文字は黒いままだった。
これは最初からiOSのみのプロジェクトだろうか…?
Author And Source
この問題について(iOSのステータスバーの文字を白くする【Xamarin.Forms(Prism)】), 我々は、より多くの情報をここで見つけました https://qiita.com/tomatosum/items/6e35076d23aab7993731著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .