-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigationController.cs
49 lines (46 loc) · 1.99 KB
/
NavigationController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using Foundation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIKit;
namespace Docutain_SDK_Example_Xamarin_iOS
{
public class NavigationController : UINavigationController
{
public NavigationController(UIViewController rootViewController) : base(rootViewController)
{
SetBarColors();
}
public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
{
base.TraitCollectionDidChange(previousTraitCollection);
if(UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
if (TraitCollection.HasDifferentColorAppearanceComparedTo(previousTraitCollection))
SetBarColors();
}
}
private void SetBarColors()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
bool isDark = TraitCollection.UserInterfaceStyle == UIUserInterfaceStyle.Dark;
var navbarAppearance = new UINavigationBarAppearance();
var TopBarsBackgroundColor = isDark ? UIColor.FromRGB(42, 42, 42) : UIColor.FromRGB(76, 175, 80);
var TopBarsForegroundColor = isDark ? UIColor.FromRGBA(255, 255, 255, 222) : UIColor.FromRGB(255, 255, 255);
navbarAppearance.BackgroundColor = TopBarsBackgroundColor;
navbarAppearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = TopBarsForegroundColor };
NavigationBar.StandardAppearance = navbarAppearance;
NavigationBar.ScrollEdgeAppearance = navbarAppearance;
}
else
{
// Fallback on earlier versions
NavigationBar.BarTintColor = UIColor.FromRGB(76, 175, 80);
NavigationBar.TitleTextAttributes = new UIStringAttributes { ForegroundColor = UIColor.White };
}
NavigationBar.TintColor = UIColor.White;
}
}
}