forked from xamarin/ios-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomCell.cs
executable file
·74 lines (60 loc) · 2.12 KB
/
CustomCell.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
using Foundation;
using UIKit;
using System;
using System.Collections.Generic;
using CoreGraphics;
namespace MonoDevelopTouchCells {
[Register]
public class CustomCell : UITableViewCell {
public string Title {
get { return this.TextLabel.Text; }
set { this.TextLabel.Text = value; }
}
public bool Checked { get; set; }
public UIButton CheckButton { get; set; }
public CustomCell (UITableViewCellStyle style, string reuseIdentifier) : base (style, reuseIdentifier)
{
this.Accessory = UITableViewCellAccessory.DetailDisclosureButton;
// cell's title label
TextLabel.BackgroundColor = this.BackgroundColor;
TextLabel.Opaque = false;
TextLabel.TextColor = UIColor.Black;
TextLabel.HighlightedTextColor = UIColor.White;
TextLabel.Font = UIFont.BoldSystemFontOfSize (18f);
// cell's check button
CheckButton = new UIButton () {
Frame = CGRect.Empty,
VerticalAlignment = UIControlContentVerticalAlignment.Center,
HorizontalAlignment = UIControlContentHorizontalAlignment.Center,
BackgroundColor = this.BackgroundColor,
};
CheckButton.TouchDown += CheckButtonTouchDown;
ContentView.AddSubview (this.CheckButton);
}
public override void LayoutSubviews ()
{
base.LayoutSubviews ();
this.TextLabel.Frame = new CGRect (
this.ContentView.Bounds.Left + 40f,
8f,
this.ContentView.Bounds.Width,
30f);
// layout the check button image
UIImage checkedImage = UIImage.FromFile ("images/checked.png");
CheckButton.Frame = new CGRect (
this.ContentView.Bounds.Left + 10f,
12f,
checkedImage.Size.Width,
checkedImage.Size.Height);
UIImage image = this.Checked ? checkedImage : UIImage.FromFile ("images/unchecked.png");
UIImage newImage = image.StretchableImage (12, 0);
CheckButton.SetBackgroundImage (newImage, UIControlState.Normal);
}
public void CheckButtonTouchDown (object sender, EventArgs e)
{
this.Checked = !this.Checked;
UIImage checkImage = this.Checked ? UIImage.FromFile ("images/checked.png") : UIImage.FromFile ("images/unchecked.png");
this.CheckButton.SetImage (checkImage, UIControlState.Normal);
}
}
}