Páginas

Rounding up the corners of a UIView, Monotouch c# version

Today I needed to round some corners of an UIView in an app I'm developing and I remember a great article from our friends of Infinixsoft at http://infinixsoft.com/2012/09/rounding-up-the-corners-of-a-uiview/

But, as I'm a Monotouch c# developer and the article was written in objetive C here's the port:


using MonoTouch.UIKit;
using MonoTouch.CoreAnimation;
using System.Drawing;


public static class Utils
{
        public static void RoundView(this UIView self, UIRectCorner rectCorner, float radius)
        {
            var maskPath = UIBezierPath.FromRoundedRect(self.Bounds, rectCorner, new SizeF(radius, radius));
            var maskLayer = new CAShapeLayer();
            maskLayer.Frame = self.Bounds;
            maskLayer.Path = maskPath.CGPath;
            self.Layer.Mask = maskLayer;
            maskLayer.Dispose();
        }
}

I developed it as static extension method of UIView, so to use it just (for eg)

NavigationController.NavigationBar.RoundView(UIRectCorner.TopLeft | UIRectCorner.TopRight, 5.0f);

Enjoy it!
https://twitter.com/vackup



No hay comentarios.:

Publicar un comentario