forked from syncfusion/xamarin-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabViewOptionsPage.cs
264 lines (237 loc) · 10.5 KB
/
TabViewOptionsPage.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#region Copyright Syncfusion Inc. 2001-2022.
// Copyright Syncfusion Inc. 2001-2022. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// [email protected]. Any infringement will be prosecuted under
// applicable laws.
#endregion
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using CoreGraphics;
using Syncfusion.iOS.TabView;
using UIKit;
namespace SampleBrowser
{
internal class CustomTextDelegate : UITextFieldDelegate
{
TabViewOptionsPage optionsPage;
public CustomTextDelegate(TabViewOptionsPage page)
{
optionsPage = page;
}
public override bool ShouldBeginEditing(UITextField textField)
{
optionsPage.HandleAction((int)textField.Tag);
return false;
}
}
public class TabViewOptionsPage : UIView
{
UILabel tabdisplaymodelabel;
UILabel tabpositionlabel;
UILabel selectionindicatorlabel;
UILabel overflowmodelabel;
UITextField tabdisplaymodeEntry;
UITextField tabpositionEntry;
UITextField selectionindicatorEntry;
UITextField overflowmodeEntry;
internal UIPickerView picker;
internal UIButton doneButton;
internal PickerModel model;
internal SfTabView sftabView;
int clickedtag = 0;
private string selectedType;
internal IList<string> displaymodelist = new List<string>();
internal IList<string> positionlist = new List<string>();
internal IList<string> selectionindicatorlist = new List<string>();
internal IList<string> overflowlist = new List<string>();
public TabViewOptionsPage()
{
var customDelegate = new CustomTextDelegate(this);
AddData();
tabdisplaymodelabel = new UILabel();
tabdisplaymodelabel.Text = "Tab Display Mode";
tabpositionlabel = new UILabel();
tabpositionlabel.Text = "Tab Position";
selectionindicatorlabel = new UILabel();
selectionindicatorlabel.Text = "Selection Type";
overflowmodelabel = new UILabel();
overflowmodelabel.Text = "Overflow Mode";
tabdisplaymodeEntry = new UITextField();
tabdisplaymodeEntry.Tag = 1;
tabdisplaymodeEntry.Layer.BorderColor = UIColor.LightGray.CGColor;
tabdisplaymodeEntry.Layer.BorderWidth = 1;
tabdisplaymodeEntry.Layer.CornerRadius = 5;
tabdisplaymodeEntry.TextAlignment = UITextAlignment.Center;
tabdisplaymodeEntry.Delegate = customDelegate;
tabdisplaymodeEntry.Text = "Image";
tabpositionEntry = new UITextField();
tabpositionEntry.Tag = 2;
tabpositionEntry.Layer.BorderColor = UIColor.LightGray.CGColor;
tabpositionEntry.Layer.BorderWidth = 1;
tabpositionEntry.Layer.CornerRadius = 5;
tabpositionEntry.TextAlignment = UITextAlignment.Center;
tabpositionEntry.Delegate = customDelegate;
tabpositionEntry.Text = "Top";
selectionindicatorEntry = new UITextField();
selectionindicatorEntry.Tag = 3;
selectionindicatorEntry.Layer.BorderColor = UIColor.LightGray.CGColor;
selectionindicatorEntry.Layer.BorderWidth = 1;
selectionindicatorEntry.Layer.CornerRadius = 5;
selectionindicatorEntry.TextAlignment = UITextAlignment.Center;
selectionindicatorEntry.Delegate = customDelegate;
selectionindicatorEntry.Text = "Bottom";
overflowmodeEntry = new UITextField();
overflowmodeEntry.Tag = 4;
overflowmodeEntry.Layer.BorderColor = UIColor.LightGray.CGColor;
overflowmodeEntry.Layer.BorderWidth = 1;
overflowmodeEntry.Layer.CornerRadius = 5;
overflowmodeEntry.TextAlignment = UITextAlignment.Center;
overflowmodeEntry.Delegate = customDelegate;
overflowmodeEntry.Text = "Scroll";
Add(tabdisplaymodelabel);
Add(tabpositionlabel);
Add(selectionindicatorlabel);
Add(overflowmodelabel);
Add(tabdisplaymodeEntry);
Add(tabpositionEntry);
Add(selectionindicatorEntry);
Add(overflowmodeEntry);
InitializePicker();
}
void InitializePicker()
{
model = new PickerModel(displaymodelist);
model.PickerChanged += PickerIndexChanged;
picker = new UIPickerView();
picker.Model = model;
picker.ShowSelectionIndicator = true;
picker.Hidden = true;
picker.BackgroundColor = UIColor.White;
//DoneButton
doneButton = new UIButton();
doneButton.SetTitle("Done\t", UIControlState.Normal);
doneButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Right;
doneButton.BackgroundColor = UIColor.FromRGB(240, 240, 240);
doneButton.SetTitleColor(UIColor.Black, UIControlState.Normal);
doneButton.Hidden = true;
doneButton.TouchUpInside += HidePicker;
Add(picker);
Add(doneButton);
}
void AddData()
{
displaymodelist.Add("Image");
displaymodelist.Add("Text");
displaymodelist.Add("Image with Text");
displaymodelist.Add("No Header");
positionlist.Add("Top");
positionlist.Add("Bottom");
selectionindicatorlist.Add("Top");
selectionindicatorlist.Add("Bottom");
selectionindicatorlist.Add("Fill");
overflowlist.Add("Scroll");
overflowlist.Add("DropDown");
}
public override void LayoutSubviews()
{
var height = this.Frame.Height;
picker.Frame = new CGRect(0, height/3 - 5, this.Frame.Size.Width, height / 3);
doneButton.Frame = new CGRect(0,(height / 3)-5, this.Frame.Size.Width, 40);
tabdisplaymodelabel.Frame = new CGRect(10, 0, this.Frame.Width - 20, 30);
tabdisplaymodeEntry.Frame = new CGRect(10, 30, this.Frame.Width - 20, 30);
tabpositionlabel.Frame = new CGRect(10, 80, this.Frame.Width - 20, 30);
tabpositionEntry.Frame = new CGRect(10, 110, this.Frame.Width - 20, 30);
overflowmodelabel.Frame = new CGRect(10, 160, this.Frame.Width - 20, 30);
overflowmodeEntry.Frame = new CGRect(10, 190, this.Frame.Width - 20, 30);
selectionindicatorlabel.Frame = new CGRect(10, 240, this.Frame.Width - 20, 30);
selectionindicatorEntry.Frame = new CGRect(10, 270, this.Frame.Width - 20, 30);
base.LayoutSubviews();
}
private void PickerIndexChanged(object sender, PickerChangedEventArgs e)
{
this.selectedType = e.SelectedValue;
}
private void SetDefaultValueForPicker(IList<string> currentTabViewMode)
{
if (this.selectedType == null)
{
this.selectedType = currentTabViewMode[0];
}
}
void HidePicker(object sender, EventArgs e)
{
switch (clickedtag)
{
case 1:
this.SetDefaultValueForPicker(this.displaymodelist);
if (this.selectedType == "Image")
sftabView.DisplayMode = TabDisplayMode.Image;
else if (this.selectedType == "Text")
sftabView.DisplayMode = TabDisplayMode.Text;
else if (this.selectedType == "Image with Text")
sftabView.DisplayMode = TabDisplayMode.ImageWithText;
else
sftabView.DisplayMode = TabDisplayMode.NoHeader;
tabdisplaymodeEntry.Text = sftabView.DisplayMode.ToString();
break;
case 2:
this.SetDefaultValueForPicker(this.positionlist);
if (this.selectedType == "Top")
sftabView.TabHeaderPosition = TabHeaderPosition.Top;
else
sftabView.TabHeaderPosition = TabHeaderPosition.Bottom;
tabpositionEntry.Text = sftabView.TabHeaderPosition.ToString();
break;
case 3:
this.SetDefaultValueForPicker(this.selectionindicatorlist);
if (this.selectedType == "Top")
sftabView.SelectionIndicatorSettings.Position = SelectionIndicatorPosition.Top;
else if (this.selectedType == "Fill")
sftabView.SelectionIndicatorSettings.Position = SelectionIndicatorPosition.Fill;
else
sftabView.SelectionIndicatorSettings.Position = SelectionIndicatorPosition.Bottom;
selectionindicatorEntry.Text = sftabView.SelectionIndicatorSettings.Position.ToString();
break;
case 4:
this.SetDefaultValueForPicker(this.overflowlist);
if (this.selectedType == "Scroll")
sftabView.OverflowMode = OverflowMode.Scroll;
else
sftabView.OverflowMode = OverflowMode.DropDown;
overflowmodeEntry.Text = sftabView.OverflowMode.ToString();
break;
}
doneButton.Hidden = true;
picker.Hidden = true;
this.BecomeFirstResponder();
}
internal void HandleAction(int tag)
{
clickedtag = tag;
switch (tag)
{
case 1:
model = new PickerModel(displaymodelist);
break;
case 2:
model = new PickerModel(positionlist);
break;
case 3:
model = new PickerModel(selectionindicatorlist);
break;
case 4:
model = new PickerModel(overflowlist);
break;
}
model.PickerChanged -= PickerIndexChanged;
model.PickerChanged += PickerIndexChanged;
picker.Model = model;
picker.ReloadAllComponents();
doneButton.Hidden = false;
picker.Hidden = false;
BecomeFirstResponder();
}
}
}