MakeRoundedRectPath() public static méthode

Creates a path for a rectangle with rounded corners
public static MakeRoundedRectPath ( RectangleF rect, float radius ) : CGPath
rect System.Drawing.RectangleF /// The rectangle bounds ///
radius float /// The size of the rounded corners ///
Résultat CGPath
Exemple #1
0
        public static void FillRoundedRect(CGContext ctx, RectangleF rect, float radius)
        {
            var p = GraphicsUtil.MakeRoundedRectPath(rect, radius);

            ctx.AddPath(p);
            ctx.FillPath();
        }
Exemple #2
0
        public override void Draw(RectangleF rect)
        {
            var context = UIGraphics.GetCurrentContext();
            var bounds  = Bounds;

            UIColor background = Enabled ? pressed ? HighlightedColor : NormalColor : DisabledColor;
            float   alpha      = 1;

            CGPath container;

            container = GraphicsUtil.MakeRoundedRectPath(bounds, 14);
            context.AddPath(container);
            context.Clip();

            using (var cs = CGColorSpace.CreateDeviceRGB()){
                var topCenter    = new PointF(bounds.GetMidX(), 0);
                var midCenter    = new PointF(bounds.GetMidX(), bounds.GetMidY());
                var bottomCenter = new PointF(bounds.GetMidX(), bounds.GetMaxY());

                using (var gradient = new CGGradient(cs, new float [] { 0.23f, 0.23f, 0.23f, alpha, 0.47f, 0.47f, 0.47f, alpha }, new float [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }

                container = GraphicsUtil.MakeRoundedRectPath(bounds.Inset(1, 1), 13);
                context.AddPath(container);
                context.Clip();
                using (var gradient = new CGGradient(cs, new float [] { 0.05f, 0.05f, 0.05f, alpha, 0.15f, 0.15f, 0.15f, alpha }, new float [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }

                var nb = bounds.Inset(4, 4);
                container = GraphicsUtil.MakeRoundedRectPath(nb, 10);
                context.AddPath(container);
                context.Clip();

                background.SetFill();
                context.FillRect(nb);

                using (var gradient = new CGGradient(cs, new float [] { 1, 1, 1, .35f, 1, 1, 1, 0.06f }, new float [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, midCenter, 0);
                }
                context.SetLineWidth(2);
                context.AddPath(container);
                context.ReplacePathWithStrokedPath();
                context.Clip();

                using (var gradient = new CGGradient(cs, new float [] { 1, 1, 1, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f }, new float [] { 0, 1 })){
                    context.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }
            }
        }