2013-10-10 34 views
0

我想在我的MvxTableViewController的每個tablevievcell中繪製一個矩形。 我有一個自定義cellLabel延伸的UIView在MvxTableViewCell中繪圖

namespace Next.Client.Application.iOS.Views.UI 
{ 
    [Register("CellLabel")] 
    public class CellLabel : UIView 
    { 
     public CellLabel() 
     { 
      Initialize(); 
     } 

     public CellLabel(RectangleF bounds) 
      : base(bounds) 
     { 
      Initialize(); 
     } 

     void Initialize() 
     { 
      BackgroundColor = UIColor.Red; 
     } 

     public override void Draw(RectangleF rect) 
     { 
      base.Draw(rect); 

      //get graphics context 
      using (CGContext gc = UIGraphics.GetCurrentContext()) 
      { 
       //set up drawing attributes 
       gc.SetLineWidth(1); 
       UIColor.Blue.SetFill(); 
       UIColor.Red.SetStroke(); 

       //create geometry 
       var path = new CGPath(); 

       path.AddLines(new PointF[]{ 
         new PointF (0, 45), 
         new PointF (80, 45), 
         new PointF (90, 50), 
         new PointF (0, 50) 
       }); 

       path.CloseSubpath(); 

       //add geometry to graphics context and draw it 
       gc.AddPath(path); 
       gc.DrawPath(CGPathDrawingMode.FillStroke); 
      } 
     } 
    } 
} 

和自定義單元格凡在

namespace Next.Client.Application.iOS 
{ 
    public partial class ObservationCell : MvxTableViewCell 
    { 
     public static readonly UINib Nib = UINib.FromName ("ObservationCell", NSBundle.MainBundle); 
     public static readonly NSString Key = new NSString ("ObservationCell"); 

     private CellLabel _labelView; 

     public ObservationCell (IntPtr handle) : base (handle) 
     { 
      _labelView = new CellLabel(); 
      this.AddSubview(_labelView); 

      this.DelayBind(() => { 
       var set = this.CreateBindingSet<ObservationCell, Observation>(); 
       set.Bind(MainLbl).To(observation => observation.BrutText); 
       set.Bind(SubLeftLbl).To(observation => observation.Praticien.Personne.DisplayFullName); 
       set.Bind(SubRightLbl).To(observation => observation.DateTimeHumanShort); 
       set.Apply(); 
      }); 
     } 

     public static ObservationCell Create() 
     { 
      return (ObservationCell)Nib.Instantiate (null, null) [0]; 
     } 
    } 
} 

畫,但沒有顯示出來:/ 任何想法?

回答

0

您CellLabel目前不似乎有任何框架 - 所以它可能正在制定中(0,0,0,0)

嘗試:

 _labelView = new CellLabel(new RectangleF(0,0,320,100)); 
     this.AddSubview(_labelView); 

如果添加一個CellLabel(IntPtr)構造函數,那麼你也可以使用CellLabel作爲XIB編輯器中的一個類型 - 它不會在編輯器中完全繪製,但編輯器將允許您將它指定爲類型,並且它將在運行時正確加載。


最後要注意的......我不認爲我會稱之爲標籤 - 可能會造成混淆誰以後閱讀代碼的人。

+0

謝謝我完全忘了框架確實:) – kitensei