示例#1
0
        internal static void UpdateMauiCALayer(this UIView nativeView, IBorder border)
        {
            CALayer?backgroundLayer = nativeView.Layer as MauiCALayer;

            if (backgroundLayer == null)
            {
                backgroundLayer = nativeView.Layer?.Sublayers?
                                  .FirstOrDefault(x => x is MauiCALayer);

                if (backgroundLayer == null)
                {
                    backgroundLayer = new MauiCALayer
                    {
                        Name = ViewExtensions.BackgroundLayerName
                    };

                    nativeView.BackgroundColor = UIColor.Clear;
                    nativeView.InsertBackgroundLayer(backgroundLayer, 0);
                }
            }

            if (backgroundLayer is MauiCALayer mauiCALayer)
            {
                mauiCALayer.SetBackground(border.Background);
                mauiCALayer.SetBorderBrush(border.Stroke);
                mauiCALayer.SetBorderWidth(border.StrokeThickness);
                mauiCALayer.SetBorderDash(border.StrokeDashPattern, border.StrokeDashOffset);
                mauiCALayer.SetBorderMiterLimit(border.StrokeMiterLimit);
                mauiCALayer.SetBorderLineJoin(border.StrokeLineJoin);
                mauiCALayer.SetBorderLineCap(border.StrokeLineCap);
                mauiCALayer.SetBorderShape(border.Shape);
            }
        }
示例#2
0
        internal static void UpdateMauiCALayer(this UIView platformView, IBorderStroke?border)
        {
            CALayer?backgroundLayer = platformView.Layer as MauiCALayer;

            if (backgroundLayer == null)
            {
                backgroundLayer = platformView.Layer?.Sublayers?
                                  .FirstOrDefault(x => x is MauiCALayer);

                if (backgroundLayer == null)
                {
                    backgroundLayer = new MauiCALayer
                    {
                        Name = ViewExtensions.BackgroundLayerName
                    };

                    platformView.BackgroundColor = UIColor.Clear;
                    platformView.InsertBackgroundLayer(backgroundLayer, 0);
                }
            }

            if (backgroundLayer is MauiCALayer mauiCALayer)
            {
                backgroundLayer.Frame = platformView.Bounds;

                if (border is IView view)
                {
                    mauiCALayer.SetBackground(view.Background);
                }
                else
                {
                    mauiCALayer.SetBackground(new SolidPaint(Colors.Transparent));
                }

                mauiCALayer.SetBorderBrush(border?.Stroke);
                mauiCALayer.SetBorderWidth(border?.StrokeThickness ?? 0);
                mauiCALayer.SetBorderDash(border?.StrokeDashPattern, border?.StrokeDashOffset ?? 0);
                mauiCALayer.SetBorderMiterLimit(border?.StrokeMiterLimit ?? 0);

                if (border != null)
                {
                    mauiCALayer.SetBorderLineJoin(border.StrokeLineJoin);
                    mauiCALayer.SetBorderLineCap(border.StrokeLineCap);
                }

                mauiCALayer.SetBorderShape(border?.Shape);
            }

            if (platformView is ContentView contentView)
            {
                contentView.Clip = border;
            }
        }