예제 #1
0
        public override void Draw(Canvas canvas)
        {
            BoxViewRoundedCorners rbv = (BoxViewRoundedCorners)this.Element;

            Rect rc = new Rect();

            GetDrawingRect(rc);

            Rect interior = rc;

            interior.Inset((int)rbv.StrokeThickness, (int)rbv.StrokeThickness);

            Paint p = new Paint()
            {
                Color     = rbv.FillColor.ToAndroid(),
                AntiAlias = true,
            };

            canvas.DrawRoundRect(new RectF(interior), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p);

            p.Color       = rbv.StrokeColor.ToAndroid();
            p.StrokeWidth = (float)rbv.StrokeThickness;
            p.SetStyle(Paint.Style.Stroke);

            canvas.DrawRoundRect(new RectF(rc), (float)rbv.CornerRadius, (float)rbv.CornerRadius, p);

            return;
        }
        public override void Draw(CGRect rect)
        {
            BoxViewRoundedCorners cbv = (BoxViewRoundedCorners)Element;

            using (var context = UIGraphics.GetCurrentContext())
            {
                context.SetFillColor(cbv.FillColor.ToCGColor());
                context.SetStrokeColor(cbv.StrokeColor.ToCGColor());
                context.SetLineWidth((float)cbv.StrokeThickness);

                CoreGraphics.CGRect rc = this.Bounds.Inset((nint)cbv.StrokeThickness, (nint)cbv.StrokeThickness);

                nfloat radius = (nfloat)cbv.CornerRadius;
                //radius = (nfloat)Math.Max (0, Math.Min (radius, Math.Max ((float)rc.Height / 2, (float)rc.Width / 2)));

                CGPath strokePath = CGPath.FromRoundedRect(rc, radius, radius);
                context.AddPath(strokePath);
                context.DrawPath(CGPathDrawingMode.FillStroke);

                if (cbv.HasShadow)
                {
                    NativeView.Layer.ShadowColor   = UIColor.Black.CGColor;
                    NativeView.Layer.ShadowOffset  = new System.Drawing.SizeF(3, 3);
                    NativeView.Layer.ShadowOpacity = 1;
                    NativeView.Layer.ShadowRadius  = 5;
                }
                else
                {
                    NativeView.Layer.ShadowColor   = UIColor.Clear.CGColor;
                    NativeView.Layer.ShadowOffset  = new System.Drawing.SizeF();
                    NativeView.Layer.ShadowOpacity = 0;
                    NativeView.Layer.ShadowRadius  = 0;
                }
            }

            return;
        }