/
_9767CustomRenderer.cs
50 lines (44 loc) · 1.57 KB
/
_9767CustomRenderer.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
50
using CoreAnimation;
using CoreGraphics;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.iOS;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(Issue9767NavigationPage), typeof(_9767CustomRenderer))]
namespace Xamarin.Forms.ControlGallery.iOS
{
public class _9767CustomRenderer : NavigationRenderer
{
public _9767CustomRenderer() : base()
{
}
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
UpdateColors();
UpdateGradientView();
}
void UpdateColors()
{
UINavigationBar.Appearance.BarTintColor = UIColor.FromPatternImage(UIImage.FromFile("coffee.png"));
UINavigationBar.Appearance.TintColor = UIColor.Yellow;
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes { TextColor = UIColor.Blue });
}
void UpdateGradientView()
{
var gradientLayer = new CAGradientLayer
{
Bounds = NavigationBar.Bounds,
Colors = new CGColor[] { Color.Blue.ToCGColor(), Color.Purple.ToCGColor() },
EndPoint = new CGPoint(0.0, 0.5),
StartPoint = new CGPoint(1.0, 0.5)
};
UIGraphics.BeginImageContext(gradientLayer.Bounds.Size);
gradientLayer.RenderInContext(UIGraphics.GetCurrentContext());
UIImage image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
NavigationBar.SetBackgroundImage(image, UIBarMetrics.Default);
}
}
}