コード例 #1
0
		CAShapeLayer GetMaskShape (ViewMaskerType maskType, Xamarin.Forms.Size size)
		{
			var layer = new CAShapeLayer ();
			layer.FillColor = UIColor.White.CGColor;
			layer.StrokeColor = UIColor.White.CGColor;
			layer.LineWidth = 0;
			UIBezierPath path = null;
			var bounds = new CGRect (0, 0, size.Width, size.Height);

			switch (maskType) {
			case ViewMaskerType.Circle:
				path = UIBezierPath.FromRoundedRect (bounds, (nfloat)Math.Max (size.Width, size.Height));
				break;
			case ViewMaskerType.Triangle:
				var point1 = new CGPoint (0, size.Height);
				var point2 = new CGPoint (size.Width, size.Height);
				var point3 = new CGPoint (size.Width / 2, 0);
				path = new UIBezierPath ();
				path.MoveTo (point1);
				path.AddLineTo (point2);
				path.AddLineTo (point3);
				path.AddLineTo (point1);
				path.ClosePath ();
				path.Fill ();
				break;
			case ViewMaskerType.Square:
				var smallRectangle = UIBezierPath.FromRect (bounds.Inset (50, 50));
				path = UIBezierPath.FromRoundedRect (bounds, 20);
				break;
			default:
				throw new ArgumentOutOfRangeException ();
			}
			layer.Path = path.CGPath;
			return layer;
		}
コード例 #2
0
		public void ApplyMaskToView (Xamarin.Forms.View view, ViewMaskerType maskType)
		{
			var renderer = view.GetRenderer ();
			var nativeView = renderer.NativeView;
			if (maskType == ViewMaskerType.None) {
				view.SizeChanged -= OnSizeChanged;
				nativeView.Layer.Mask = null;
			} else {
				var maskLayer = GetMaskShape (maskType, new Xamarin.Forms.Size (view.Width, view.Height));
				maskLayer.Frame = nativeView.Bounds;
				nativeView.Layer.Mask = maskLayer;
				view.SizeChanged += OnSizeChanged;
			}
			nativeView.Tag = (int)maskType;
			
		}
コード例 #3
0
        public void ApplyMaskToView(Xamarin.Forms.View view, ViewMaskerType maskType)
        {
            var renderer   = view.GetRenderer();
            var nativeView = renderer.NativeView;

            if (maskType == ViewMaskerType.None)
            {
                view.SizeChanged     -= OnSizeChanged;
                nativeView.Layer.Mask = null;
            }
            else
            {
                var maskLayer = GetMaskShape(maskType, new Xamarin.Forms.Size(view.Width, view.Height));
                maskLayer.Frame       = nativeView.Bounds;
                nativeView.Layer.Mask = maskLayer;
                view.SizeChanged     += OnSizeChanged;
            }
            nativeView.Tag = (int)maskType;
        }
コード例 #4
0
        CAShapeLayer GetMaskShape(ViewMaskerType maskType, Xamarin.Forms.Size size)
        {
            var layer = new CAShapeLayer();

            layer.FillColor   = UIColor.White.CGColor;
            layer.StrokeColor = UIColor.White.CGColor;
            layer.LineWidth   = 0;
            UIBezierPath path   = null;
            var          bounds = new CGRect(0, 0, size.Width, size.Height);

            switch (maskType)
            {
            case ViewMaskerType.Circle:
                path = UIBezierPath.FromRoundedRect(bounds, (nfloat)Math.Max(size.Width, size.Height));
                break;

            case ViewMaskerType.Triangle:
                var point1 = new CGPoint(0, size.Height);
                var point2 = new CGPoint(size.Width, size.Height);
                var point3 = new CGPoint(size.Width / 2, 0);
                path = new UIBezierPath();
                path.MoveTo(point1);
                path.AddLineTo(point2);
                path.AddLineTo(point3);
                path.AddLineTo(point1);
                path.ClosePath();
                path.Fill();
                break;

            case ViewMaskerType.Square:
                var smallRectangle = UIBezierPath.FromRect(bounds.Inset(50, 50));
                path = UIBezierPath.FromRoundedRect(bounds, 20);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            layer.Path = path.CGPath;
            return(layer);
        }
コード例 #5
0
		public static void ApplyMask (this Xamarin.Forms.View view, ViewMaskerType maskType)
		{
			ViewExtensionProvider.ApplyMaskToView (view, maskType);
		}
コード例 #6
0
		public void ApplyMaskToView (Xamarin.Forms.View view, ViewMaskerType maskType)
		{
			//we need to wrap the view inside another view
		}
コード例 #7
0
 public void ApplyMaskToView(Xamarin.Forms.View view, ViewMaskerType maskType)
 {
     //we need to wrap the view inside another view
 }
コード例 #8
0
 public static void ApplyMask(this Xamarin.Forms.View view, ViewMaskerType maskType)
 {
     ViewExtensionProvider.ApplyMaskToView(view, maskType);
 }