forked from jonathanfontaine/iOSMaterialShowcase.Xamarin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaterialShowcaseInstructionView.cs
151 lines (130 loc) · 5.67 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using CoreGraphics;
using UIKit;
using SlatePages.iOS;
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 string dismissText;
public UIColor dismissTextColor;
public UIColor dismissBackgroundColor;
public UIFont dismissTextFont;
public UIButton dismissButton;
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);
}
private void AddDismissButton()
{
var paddingTop = 20f;
dismissButton = new UIButton ();
if (dismissTextFont != null)
dismissButton.TitleLabel.Font = dismissTextFont;
else
dismissButton.TitleLabel.Font = UIFont.SystemFontOfSize (secondaryTextSize);
dismissButton.SetTitleColor(dismissTextColor, UIControlState.Normal);
dismissButton.BackgroundColor = dismissBackgroundColor;
dismissButton.SetTitle (dismissText, UIControlState.Normal);
dismissButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Center;
dismissButton.Frame = new CGRect (0, primaryLabel.Frame.Height + secondaryLabel.Frame.Height + paddingTop, Frame.Width, 0);
dismissButton.SizeToFit ();
dismissButton.SetFrameWidth(dismissButton.Frame.Width + 30f);
AddSubview (dismissButton);
Frame = new CGRect (Frame.GetMinX (),
Frame.GetMinY (),
UIScreen.MainScreen.Bounds.Width,
primaryLabel.Frame.Height + secondaryLabel.Frame.Height + dismissButton.Frame.Height + paddingTop);
}
public override void LayoutSubviews ()
{
base.LayoutSubviews ();
AddPrimaryLabel ();
AddSecondaryLabel ();
if (!string.IsNullOrEmpty (dismissText))
AddDismissButton ();
foreach (var subview in Subviews)
subview.UserInteractionEnabled = false;
if (dismissButton != null)
{
dismissButton.UserInteractionEnabled = true;
}
}
}
}