-
Notifications
You must be signed in to change notification settings - Fork 2
/
MaterialShowcaseInstructionView.cs
116 lines (97 loc) · 4.38 KB
/
MaterialShowcaseInstructionView.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using CoreGraphics;
using UIKit;
namespace iOSMaterialShowcase.Xamarin
{
public class MaterialShowcaseInstructionView : UIView
{
internal const float PrimaryTextSize = 20f;
internal const float SecondaryTextSize = 15f;
internal static UIColor PrimaryTextColor = UIColor.White;
internal static UIColor SecondaryTextColor = UIColor.White.ColorWithAlpha(.87f);
internal const string PrimaryDefaultText = "";
internal const string SecondaryDefaultText = "";
public UILabel primaryLabel;
public UILabel secondaryLabel;
// Text
public string primaryText;
public string secondaryText;
public UIColor primaryTextColor;
public UIColor secondaryTextColor;
public float primaryTextSize;
public float secondaryTextSize;
public UIFont primaryTextFont;
public UIFont secondaryTextFont;
public MaterialShowcaseInstructionView()
: base(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 0))
{
Configure();
}
private void Configure()
{
SetDefaultProperties();
}
private void SetDefaultProperties()
{
// Text
primaryText = PrimaryDefaultText;
secondaryText = SecondaryDefaultText;
primaryTextColor = PrimaryTextColor;
secondaryTextColor = SecondaryTextColor;
primaryTextSize = PrimaryTextSize;
secondaryTextSize = SecondaryTextSize;
}
/// Configures and adds primary label view
private void AddPrimaryLabel()
{
primaryLabel = new UILabel();
if (primaryTextFont != null)
primaryLabel.Font = primaryTextFont;
else
primaryLabel.Font = UIFont.BoldSystemFontOfSize(primaryTextSize);
primaryLabel.TextColor = primaryTextColor;
primaryLabel.TextAlignment = UITextAlignment.Left;
primaryLabel.Lines = 0;
primaryLabel.LineBreakMode = UILineBreakMode.WordWrap;
primaryLabel.Text = primaryText;
//// Calculate x position
//MaterialShowcase materialShowcase = (MaterialShowcase)Superview;
//var xPosition = materialShowcase.backgroundView.Frame.GetMinX() > 0 ?
// materialShowcase.backgroundView.Frame.GetMinX() + MaterialShowcase.labelMargin : MaterialShowcase.labelMargin;
//// Calculate y position
//float yPosition;
//if (materialShowcase.GetTargetPosition(materialShowcase.targetView, materialShowcase.containerView) == MaterialShowcaseExtension.TargetPosition.Above)
// yPosition = (float)Center.Y + MaterialShowcase.textCenterOffset;
//else
// yPosition = (float)Center.Y - MaterialShowcase.textCenterOffset - MaterialShowcase.labelDefaultHeight * 2;
primaryLabel.Frame = new CGRect(0, 0, Frame.Width, 0);
primaryLabel.SizeToFitHeight();
AddSubview(primaryLabel);
}
/// Configures and adds secondary label view
private void AddSecondaryLabel()
{
secondaryLabel = new UILabel();
if (secondaryTextFont != null)
secondaryLabel.Font = secondaryTextFont;
else
secondaryLabel.Font = UIFont.SystemFontOfSize(secondaryTextSize);
secondaryLabel.TextColor = secondaryTextColor;
secondaryLabel.TextAlignment = UITextAlignment.Left;
secondaryLabel.LineBreakMode = UILineBreakMode.WordWrap;
secondaryLabel.Text = secondaryText;
secondaryLabel.Lines = 3;
secondaryLabel.Frame = new CGRect(0, primaryLabel.Frame.Height, Frame.Width, 0);
secondaryLabel.SizeToFitHeight();
AddSubview(secondaryLabel);
Frame = new CGRect(Frame.GetMinX(), Frame.GetMinY(), UIScreen.MainScreen.Bounds.Width, primaryLabel.Frame.Height + secondaryLabel.Frame.Height);
}
public override void LayoutSubviews()
{
base.LayoutSubviews();
AddPrimaryLabel();
AddSecondaryLabel();
foreach (var subview in Subviews)
subview.UserInteractionEnabled = false;
}
}
}