我想在我的MvxTableViewController的每个tablevievcell中绘制一个矩形。 我有一个自定义的cellLabel扩展UIView
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 :(得分:0)
你的CellLabel目前似乎没有任何框架 - 所以它可能被绘制在内部(0,0,0,0)
尝试:
_labelView = new CellLabel(new RectangleF(0,0,320,100));
this.AddSubview(_labelView);
如果添加CellLabel(IntPtr)
构造函数,那么您也可以将CellLabel用作XIB编辑器中的类型 - 它不会在编辑器中完全绘制,但编辑器将允许您将其指定为类型,它将在运行时正确加载。
最后一个注意事项......我认为我不称之为标签 - 可能会让以后阅读该代码的人感到困惑。