回答編集履歴

1

より簡潔に済むように修正

2019/04/03 05:59

投稿

f-miyu
f-miyu

スコア1625

test CHANGED
@@ -1,26 +1,10 @@
1
1
  コードでステータスバーのスタイルを変更すればいいので、[カスタムレンダラー](https://docs.microsoft.com/ja-jp/xamarin/xamarin-forms/app-fundamentals/custom-renderer/)を使います。
2
2
 
3
- 以下のように`ContentPage`と`NavigationPage`をカスタマイズします。
3
+ 以下のように`NavigationPage`をカスタマイズします。
4
4
 
5
5
 
6
6
 
7
7
  **.NET Standardプロジェクト**
8
-
9
- ```C#
10
-
11
- namespace StatusBar
12
-
13
- {
14
-
15
- public class CustomContentPage : ContentPage
16
-
17
- {
18
-
19
- }
20
-
21
- }
22
-
23
- ```
24
8
 
25
9
 
26
10
 
@@ -58,36 +42,6 @@
58
42
 
59
43
  **iOSプロジェクト**
60
44
 
61
-
62
-
63
- ```C#
64
-
65
- [assembly: ExportRenderer(typeof(CustomContentPage), typeof(CustomContentPageRenderer))]
66
-
67
- namespace StatusBar.iOS
68
-
69
- {
70
-
71
- public class CustomContentPageRenderer : PageRenderer
72
-
73
- {
74
-
75
- public override UIStatusBarStyle PreferredStatusBarStyle()
76
-
77
- {
78
-
79
- return UIStatusBarStyle.LightContent;
80
-
81
- }
82
-
83
- }
84
-
85
- }
86
-
87
- ```
88
-
89
-
90
-
91
45
  ```C#
92
46
 
93
47
  [assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationRenderer))]
@@ -100,11 +54,11 @@
100
54
 
101
55
  {
102
56
 
103
- public override UIViewController ChildViewControllerForStatusBarStyle()
57
+ public override UIStatusBarStyle PreferredStatusBarStyle()
104
58
 
105
59
  {
106
60
 
107
- return VisibleViewController.ChildViewControllers.First();
61
+ return UIStatusBarStyle.LightContent;
108
62
 
109
63
  }
110
64
 
@@ -131,21 +85,3 @@
131
85
  };
132
86
 
133
87
  ```
134
-
135
-
136
-
137
- ```xml
138
-
139
- <local:CustomContentPage xmlns="http://xamarin.com/schemas/2014/forms"
140
-
141
- xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
142
-
143
- xmlns:local="clr-namespace:StatusBar"
144
-
145
- x:Class="StatusBar.Webview">
146
-
147
- <WebView Source="https://www.youtube.com" />
148
-
149
- </local:CustomContentPage>
150
-
151
- ```