Created
October 31, 2011 16:58
-
-
Save nicwise/1328002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use: | |
var floatElement = new MVFloatElement(null, null, 0.5); | |
floatElement.OnValueChange += delegate(fe) { | |
//do something with fe.Value, or floatElement.Value | |
}; | |
public class MVFloatElement : Element | |
{ | |
public bool ShowCaption; | |
public float Value; | |
public float MinValue, MaxValue; | |
static NSString skey = new NSString("MVFloatElement"); | |
UIImage Left, Right; | |
UISlider slider; | |
//ADDED THIS | |
public Action<MVFloatElement> OnValueChange; | |
public MVFloatElement(UIImage left, UIImage right, float value) | |
: base(null) | |
{ | |
Left = left; | |
Right = right; | |
MinValue = 0; | |
MaxValue = 1; | |
Value = value; | |
} | |
protected override NSString CellKey | |
{ | |
get | |
{ | |
return skey; | |
} | |
} | |
public override UITableViewCell GetCell(UITableView tv) | |
{ | |
var cell = tv.DequeueReusableCell(CellKey); | |
if (cell == null) | |
{ | |
cell = new UITableViewCell(UITableViewCellStyle.Default, CellKey); | |
cell.SelectionStyle = UITableViewCellSelectionStyle.None; | |
} | |
else | |
RemoveTag(cell, 1); | |
SizeF captionSize = new SizeF(0, 0); | |
if (Caption != null && ShowCaption) | |
{ | |
cell.TextLabel.Text = Caption; | |
captionSize = cell.TextLabel.StringSize(Caption, UIFont.FromName(cell.TextLabel.Font.Name, UIFont.LabelFontSize)); | |
captionSize.Width += 10; // Spacing | |
} | |
if (slider == null) | |
{ | |
slider = new UISlider(new RectangleF(10f + captionSize.Width, 12f, 280f - captionSize.Width, 7f)) | |
{ | |
BackgroundColor = UIColor.Clear, | |
MinValue = this.MinValue, | |
MaxValue = this.MaxValue, | |
Continuous = true, | |
Value = this.Value, | |
Tag = 1 | |
}; | |
slider.ValueChanged += delegate | |
{ | |
Value = slider.Value; | |
//CHANGE HERE | |
if (OnValueChange != null) OnValueChange(this); | |
}; | |
} | |
cell.ContentView.AddSubview(slider); | |
return cell; | |
} | |
public override string Summary() | |
{ | |
return Value.ToString(); | |
} | |
protected override void Dispose(bool disposing) | |
{ | |
if (disposing) | |
{ | |
if (slider != null) | |
{ | |
slider.Dispose(); | |
slider = null; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment