Advertisement
EENielsen

CustomCell.cs

Jun 12th, 2014
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using System;
  2. using MonoTouch.Foundation;
  3. using MonoTouch.UIKit;
  4. using System.Drawing;
  5.  
  6.  
  7. namespace Tandlaegen {
  8.     public class CustomCell: UITableViewCell  {
  9.  
  10.         UILabel headingLabel, subheadingLabel;
  11.         UIImageView imageView;
  12.  
  13.         public CustomCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
  14.         {
  15.             SelectionStyle = UITableViewCellSelectionStyle.Gray;
  16.  
  17.             imageView = new UIImageView ();
  18.  
  19.             headingLabel = new UILabel () {
  20.                 Font = UIFont.FromName("Gill Sans", 16f),
  21.                 TextColor = UIColor.White,
  22.                 BackgroundColor = UIColor.Clear
  23.             };
  24.  
  25.             subheadingLabel = new UILabel () {
  26.                 Font = UIFont.FromName("Gill Sans", 12f),
  27.                 TextColor = UIColor.White,
  28.                 TextAlignment = UITextAlignment.Center,
  29.                 BackgroundColor = UIColor.Clear,
  30.                 Lines = 0
  31.             };
  32.  
  33.             headingLabel.Lines = 0;
  34.             headingLabel.LineBreakMode = UILineBreakMode.CharacterWrap;
  35.             headingLabel.TextAlignment = UITextAlignment.Left;
  36.             headingLabel.SizeToFit ();
  37.  
  38.             subheadingLabel.Lines = 0;
  39.             subheadingLabel.LineBreakMode = UILineBreakMode.CharacterWrap;
  40.             subheadingLabel.TextAlignment = UITextAlignment.Left;
  41.             subheadingLabel.SizeToFit ();
  42.  
  43.  
  44.             ContentView.Add (subheadingLabel);
  45.             ContentView.Add (headingLabel);
  46.  
  47.             ContentView.Add (imageView);
  48.  
  49.         }
  50.  
  51.         public void UpdateCell (string caption, string subtitle, UIImage image, int type)
  52.         {  
  53.             imageView.Image = image;
  54.             headingLabel.Text = caption;
  55.             subheadingLabel.Text = subtitle;
  56.  
  57.             ContentView.BackgroundColor = UIColor.White;
  58.             headingLabel.TextColor = UIColor.Black;
  59.             subheadingLabel.TextColor = UIColor.Black;
  60.             subheadingLabel.Hidden = true;
  61.             imageView.Hidden = true;
  62.  
  63.  
  64.         }
  65.  
  66.         public override void LayoutSubviews ()
  67.         {
  68.             base.LayoutSubviews ();
  69.  
  70.             imageView.Frame = new RectangleF(ContentView.Bounds.Width - 63, 5, 33, 33);
  71.             headingLabel.Frame = new RectangleF(ContentView.Bounds.Width - (ContentView.Bounds.Width / 2), 5, ContentView.Bounds.Width - 10, 30);
  72.             headingLabel.SizeToFit ();
  73.             subheadingLabel.Frame = new RectangleF(10, 45, ContentView.Bounds.Width, 20);
  74.             subheadingLabel.SizeToFit ();
  75.  
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement