This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathButtonsViewController.xib.cs
254 lines (219 loc) · 8.57 KB
/
ButtonsViewController.xib.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
//
// Button sample in C#v
//
using System;
using UIKit;
using Foundation;
using CoreGraphics;
namespace MonoCatalog {
public partial class ButtonsViewController : UITableViewController {
//
// This datasource describes how the UITableView should render the
// contents. We have a number of sections determined by the
// samples in our container class, and 2 rows per section:
//
// Row 0: the actual styled button
// Row 1: the text information about the button
//
class DataSource : UITableViewDataSource {
ButtonsViewController bvc;
static NSString kDisplayCell_ID = new NSString ("DisplayCellID");
static NSString kSourceCell_ID = new NSString ("SourceCellID");
public DataSource (ButtonsViewController bvc)
{
this.bvc = bvc;
}
public override nint NumberOfSections (UITableView tableView)
{
return bvc.samples.Length;
}
public override string TitleForHeader (UITableView tableView, nint section)
{
return bvc.samples [section].Title;
}
public override nint RowsInSection (UITableView tableView, nint section)
{
return 2;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell;
if (indexPath.Row == 0) {
cell = tableView.DequeueReusableCell (kDisplayCell_ID);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, kDisplayCell_ID);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
} else {
// The cell is being recycled, remove the old content
UIView viewToRemove = cell.ContentView.ViewWithTag (kViewTag);
if (viewToRemove != null)
viewToRemove.RemoveFromSuperview ();
}
cell.TextLabel.Text = bvc.samples [indexPath.Section].Label;
cell.ContentView.AddSubview (bvc.samples [indexPath.Section].Button);
} else {
cell = tableView.DequeueReusableCell (kSourceCell_ID);
if (cell == null) {
// Construct the cell with reusability (the second argument is not null)
cell = new UITableViewCell (UITableViewCellStyle.Default, kSourceCell_ID);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
var label = cell.TextLabel;
label.Opaque = false;
label.TextAlignment = UITextAlignment.Center;
label.TextColor = UIColor.Gray;
label.Lines = 2;
label.HighlightedTextColor = UIColor.Black;
label.Font = UIFont.SystemFontOfSize (12f);
}
cell.TextLabel.Text = bvc.samples [indexPath.Section].Source;
}
return cell;
}
}
class TableDelegate : UITableViewDelegate {
//
// Override to provide the sizing of the rows in our table
//
public override nfloat GetHeightForRow (UITableView tableView, NSIndexPath indexPath)
{
// First row is always 50 pixes, second row 38
return indexPath.Row == 0 ? 50f : 38f;
}
}
// Load our definition from the NIB file
public ButtonsViewController () : base ("ButtonsViewController", null)
{
}
// For tagging our embedded controls at cell recylce time.
const int kViewTag = 1;
//
// Utility function that configures the various buttons that we create
//
static UIButton ButtonWithTitle (string title, CGRect frame, UIImage image, UIImage imagePressed, bool darkTextColor)
{
var button = new UIButton (frame) {
VerticalAlignment = UIControlContentVerticalAlignment.Center,
HorizontalAlignment = UIControlContentHorizontalAlignment.Center,
BackgroundColor = UIColor.Clear
};
button.SetTitle (title, UIControlState.Normal);
if (darkTextColor)
button.SetTitleColor (UIColor.Black, UIControlState.Normal);
else
button.SetTitleColor (UIColor.White, UIControlState.Normal);
var newImage = image.StretchableImage (12, 0);
button.SetBackgroundImage (newImage, UIControlState.Normal);
var newPressedImage = image.StretchableImage (12, 0);
button.SetBackgroundImage (newPressedImage, UIControlState.Highlighted);
button.Tag = kViewTag;
// To support reusable cells
button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
return button;
}
UIButton GrayButton ()
{
var background = UIImage.FromFile ("images/whiteButton.png");
var backgroundPressed = UIImage.FromFile ("images/blueButton.png");
var frame = new CGRect (182f, 5f, 106f, 40f);
//button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
return ButtonWithTitle ("Gray", frame, background, backgroundPressed, true);
}
UIButton ImageButton ()
{
var background = UIImage.FromFile ("images/whiteButton.png");
var backgroundPressed = UIImage.FromFile ("images/blueButton.png");
var frame = new CGRect (182f, 5f, 106f, 40f);
var button = ButtonWithTitle ("", frame, background, backgroundPressed, true);
button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
button.SetImage (UIImage.FromFile ("images/UIButton_custom.png"), UIControlState.Normal);
return button;
}
UIButton RoundedButtonType ()
{
var button = UIButton.FromType (UIButtonType.RoundedRect);
button.Frame = new CGRect (182f, 5f, 106f, 40f);
button.BackgroundColor = UIColor.Clear;
button.SetTitle ("Rounded", UIControlState.Normal);
button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
button.Tag = kViewTag;
// To support reusable cells
return button;
}
UIButton DetailDisclosureButton ()
{
var button = UIButton.FromType (UIButtonType.DetailDisclosure);
button.Frame = new CGRect (250f, 8f, 25f, 25f);
button.BackgroundColor = UIColor.Clear;
button.SetTitle ("Detail Disclosure", UIControlState.Normal);
button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
button.Tag = kViewTag;
// To support reusable cells
return button;
}
UIButton InfoDarkButtonType ()
{
var button = UIButton.FromType (UIButtonType.InfoDark);
button.Frame = new CGRect (250, 8f, 25f, 25f);
button.BackgroundColor = UIColor.Clear;
button.SetTitle ("Detail Disclosure", UIControlState.Normal);
button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
button.Tag = kViewTag;
button.AccessibilityLabel = "InfoDark";
// To support reusable cells
return button;
}
UIButton InfoLightButtonType ()
{
var button = UIButton.FromType (UIButtonType.InfoLight);
button.Frame = new CGRect (250, 8f, 25f, 25f);
button.BackgroundColor = UIColor.Gray;
button.SetTitle ("Detail Disclosure", UIControlState.Normal);
button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
button.Tag = kViewTag;
button.AccessibilityLabel = "InfoLight";
// To support reusable cells
return button;
}
UIButton ContactAddButtonType ()
{
var button = UIButton.FromType (UIButtonType.ContactAdd);
button.Frame = new CGRect (250, 8f, 25f, 25f);
button.BackgroundColor = UIColor.Clear;
button.SetTitle ("Detail Disclosure", UIControlState.Normal);
button.TouchDown += delegate { Console.WriteLine ("The button has been touched"); };
button.Tag = kViewTag;
button.AccessibilityLabel = "ContactAdd";
// To support reusable cells
return button;
}
struct ButtonSample {
public string Title, Label, Source;
public UIButton Button;
public ButtonSample (string t, string l, string s, UIButton b)
{
Title = t;
Label = l;
Source = s;
Button = b;
}
}
ButtonSample [] samples;
public override void ViewDidLoad ()
{
Console.WriteLine ("Buttons: View Did Load - FIrst");
base.ViewDidLoad ();
Title = "Buttons";
samples = new ButtonSample [] {
new ButtonSample ("UIButton", "Background image", "buttons.cs:\rUIButton GrayButton ()", GrayButton ()),
new ButtonSample ("UIButton", "Button with image", "buttons.cs:\rUIButton ImageButton ()", ImageButton ()),
new ButtonSample ("UIButtonRoundedRect", "Rounded Button", "buttons.cs:\rUIButton RoundedButtonType ()", RoundedButtonType ()),
new ButtonSample ("UIButtonTypeDetailDisclosure", "Detail disclosure", "buttons.cs:\rUIButton DetailDisclosureButton ()", DetailDisclosureButton ()),
new ButtonSample ("UIButtonTypeInfoLight", "Info light", "buttons.cs:\rUIButton InfoLightButtonType ()", InfoLightButtonType ()),
new ButtonSample ("UIButtonTypeInfoDark", "Info dark", "buttons.cs:\rUIButton InfoLightButtonType ()", InfoDarkButtonType ()),
new ButtonSample ("UIButtonTypeContactAdd", "Contact Add", "buttons.cs:\rUIButton ContactAddButtonType ()", ContactAddButtonType ())
};
TableView.DataSource = new DataSource (this);
TableView.Delegate = new TableDelegate ();
}
}
}