0

MvxTableViewController のすべての tablevievcell に四角形を描画したいと思います。UIView を拡張するカスタム cellLabel があります

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];
        }
    }
}

しかし、何も表示されません:/何かアイデアはありますか?

4

1 に答える 1

0

あなたの CellLabel には現在 Frame がないようです - おそらく (0,0,0,0) 内に描画されています

試す:

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

コンストラクターを追加するCellLabel(IntPtr)と、XIB エディターで CellLabel を型として使用することもできます。エディター内で完全に描画されるわけではありませんが、エディターで型として指定することができ、正しくロードされます。ランタイム。


最後に 1 つ…私はそれをラベルとは呼ばないと思います。後でコードを読む人を混乱させる可能性があります。

于 2013-10-11T08:44:18.330 に答える