summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/Cells/TextCellRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS/Cells/TextCellRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.iOS/Cells/TextCellRenderer.cs73
1 files changed, 73 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Cells/TextCellRenderer.cs b/Xamarin.Forms.Platform.iOS/Cells/TextCellRenderer.cs
new file mode 100644
index 00000000..41c43341
--- /dev/null
+++ b/Xamarin.Forms.Platform.iOS/Cells/TextCellRenderer.cs
@@ -0,0 +1,73 @@
+using System.ComponentModel;
+#if __UNIFIED__
+using UIKit;
+
+#else
+using MonoTouch.UIKit;
+#endif
+
+namespace Xamarin.Forms.Platform.iOS
+{
+ public class TextCellRenderer : CellRenderer
+ {
+ static readonly Color DefaultDetailColor = new Color(.32, .4, .57);
+ static readonly Color DefaultTextColor = Color.Black;
+
+ public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
+ {
+ var textCell = (TextCell)item;
+
+ var tvc = reusableCell as CellTableViewCell;
+ if (tvc == null)
+ tvc = new CellTableViewCell(UITableViewCellStyle.Subtitle, item.GetType().FullName);
+ else
+ tvc.Cell.PropertyChanged -= tvc.HandlePropertyChanged;
+
+ tvc.Cell = textCell;
+ textCell.PropertyChanged += tvc.HandlePropertyChanged;
+ tvc.PropertyChanged = HandlePropertyChanged;
+
+ tvc.TextLabel.Text = textCell.Text;
+ tvc.DetailTextLabel.Text = textCell.Detail;
+ tvc.TextLabel.TextColor = textCell.TextColor.ToUIColor(DefaultTextColor);
+ tvc.DetailTextLabel.TextColor = textCell.DetailColor.ToUIColor(DefaultDetailColor);
+
+ WireUpForceUpdateSizeRequested(item, tvc, tv);
+
+ UpdateIsEnabled(tvc, textCell);
+
+ UpdateBackground(tvc, item);
+
+ return tvc;
+ }
+
+ protected virtual void HandlePropertyChanged(object sender, PropertyChangedEventArgs args)
+ {
+ var tvc = (CellTableViewCell)sender;
+ var textCell = (TextCell)tvc.Cell;
+ if (args.PropertyName == TextCell.TextProperty.PropertyName)
+ {
+ tvc.TextLabel.Text = ((TextCell)tvc.Cell).Text;
+ tvc.TextLabel.SizeToFit();
+ }
+ else if (args.PropertyName == TextCell.DetailProperty.PropertyName)
+ {
+ tvc.DetailTextLabel.Text = ((TextCell)tvc.Cell).Detail;
+ tvc.DetailTextLabel.SizeToFit();
+ }
+ else if (args.PropertyName == TextCell.TextColorProperty.PropertyName)
+ tvc.TextLabel.TextColor = textCell.TextColor.ToUIColor(DefaultTextColor);
+ else if (args.PropertyName == TextCell.DetailColorProperty.PropertyName)
+ tvc.DetailTextLabel.TextColor = textCell.DetailColor.ToUIColor(DefaultTextColor);
+ else if (args.PropertyName == Cell.IsEnabledProperty.PropertyName)
+ UpdateIsEnabled(tvc, textCell);
+ }
+
+ static void UpdateIsEnabled(CellTableViewCell cell, TextCell entryCell)
+ {
+ cell.UserInteractionEnabled = entryCell.IsEnabled;
+ cell.TextLabel.Enabled = entryCell.IsEnabled;
+ cell.DetailTextLabel.Enabled = entryCell.IsEnabled;
+ }
+ }
+} \ No newline at end of file