/
MaterialFormsCheckBox.cs
52 lines (43 loc) · 1.52 KB
/
MaterialFormsCheckBox.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
51
52
using System;
using CoreGraphics;
using UIKit;
using Xamarin.Forms.Platform.iOS;
namespace Xamarin.Forms.Material.iOS
{
public class MaterialFormsCheckBox : FormsCheckBox
{
static UIImage _checked;
static UIImage _unchecked;
internal override UIBezierPath CreateBoxPath(CGRect backgroundRect) => UIBezierPath.FromRoundedRect(backgroundRect, 1);
internal override UIBezierPath CreateCheckPath() => new UIBezierPath
{
LineWidth = (nfloat).12,
LineCapStyle = CGLineCap.Round,
LineJoinStyle = CGLineJoin.Round
};
internal override void DrawCheckMark(UIBezierPath path)
{
path.MoveTo(new CGPoint(0.80f, 0.14f));
path.AddLineTo(new CGPoint(0.33f, 0.6f));
path.AddLineTo(new CGPoint(0.10f, 0.37f));
}
protected override UIImage GetCheckBoximage()
{
// Ideally I would use the static images here but when disabled it always tints them grey
// and I don't know how to make it not tint them gray
if (!Enabled && CheckBoxTintColor != Color.Default)
{
if (IsChecked)
return CreateCheckBox(CreateCheckMark()).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
return CreateCheckBox(null).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
}
if (_checked == null)
_checked = CreateCheckBox(CreateCheckMark()).ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
if (_unchecked == null)
_unchecked = CreateCheckBox(null).ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
if (IsChecked)
return _checked;
return _unchecked;
}
}
}