Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何向TableView中的分区添加阴影_C#_Ios_Xamarin.ios - Fatal编程技术网

C# 如何向TableView中的分区添加阴影

C# 如何向TableView中的分区添加阴影,c#,ios,xamarin.ios,C#,Ios,Xamarin.ios,//Top Left Right Corners var maskPathTop = UIBezierPath.FromRoundedRect(cell.Bounds, UIRectCorner.TopLeft | UIRectCorner.TopRight, new CoreGraphics.CGSize(8, 8)); var shapeLayerTop = new CAShapeLayer(); shapeLayerTop.Frame = cell.Bounds;

  //Top Left Right Corners
    var maskPathTop = UIBezierPath.FromRoundedRect(cell.Bounds, UIRectCorner.TopLeft | UIRectCorner.TopRight, new CoreGraphics.CGSize(8, 8));
    var shapeLayerTop = new CAShapeLayer();
    shapeLayerTop.Frame = cell.Bounds;
            shapeLayerTop.Path = maskPathTop.CGPath;

            //Bottom Left Right Corners
            var maskPathBottom = UIBezierPath.FromRoundedRect(cell.Bounds, UIRectCorner.BottomLeft | UIRectCorner.BottomRight, new CoreGraphics.CGSize(8, 8));
    var shapeLayerBottom = new CAShapeLayer();
    shapeLayerBottom.Frame = cell.Bounds;
            shapeLayerBottom.Path = maskPathBottom.CGPath;

            //All Corners
            var maskPathAll = UIBezierPath.FromRoundedRect(cell.Bounds, UIRectCorner.BottomLeft | UIRectCorner.BottomRight | UIRectCorner.TopLeft | UIRectCorner.TopRight, new CoreGraphics.CGSize(8, 8));
    var shapeLayerAll = new CAShapeLayer();
    shapeLayerAll.Frame = cell.Bounds;
            shapeLayerAll.Path = maskPathAll.CGPath;

            if (indexPath.Row == 0 && indexPath.Row == tableView.NumberOfRowsInSection(indexPath.Section) - 1)
            {
                cell.Layer.Mask = shapeLayerAll;
            }
            else if (indexPath.Row == 0)
            {
                cell.Layer.Mask = shapeLayerTop;

            }

            else if (indexPath.Row == tableView.NumberOfRowsInSection(indexPath.Section) - 1)
            {
                cell.Layer.Mask = shapeLayerBottom;
            }
我曾经尝试过为每个部分添加圆角,但在这个过程中,我无法为每个部分添加阴影。有人能用C#推荐吗?因为我是Xamarin iOS的初学者。
提前谢谢

创建一个新的
shadowView
shadowView.AddSubview(单元格),以下是代码示例:

public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    // Perform any additional setup after loading the view, typically from a nib.

    UILabel cell = new UILabel();
    cell.BackgroundColor = UIColor.Blue;
    cell.Text = "test";

    UIView shadowView = new UIView(new CoreGraphics.CGRect(100, 100, 200, 100));
    shadowView.Layer.ShadowColor = UIColor.Black.CGColor;
    shadowView.Layer.ShadowRadius = 8.0f;
    shadowView.Layer.ShadowOffset = new CGSize(13.0, 13.0);
    shadowView.Layer.ShadowOpacity = 0.5f;

    cell.Frame = shadowView.Bounds;

    //Top Left Right Corners
    var maskPathTop = UIBezierPath.FromRoundedRect(cell.Bounds, UIRectCorner.TopLeft | UIRectCorner.TopRight, new CoreGraphics.CGSize(8, 8));
    var shapeLayerTop = new CAShapeLayer();
    shapeLayerTop.Frame = cell.Bounds;
    //shapeLayerTop.BorderWidth = 3;
    //shapeLayerTop.BorderColor = VM.RedColor.ToNativeColor().CGColor;
    shapeLayerTop.Path = maskPathTop.CGPath;

    //Bottom Left Right Corners
    var maskPathBottom = UIBezierPath.FromRoundedRect(cell.Bounds, UIRectCorner.BottomLeft | UIRectCorner.BottomRight, new CoreGraphics.CGSize(8, 8));
    var shapeLayerBottom = new CAShapeLayer();
    shapeLayerBottom.Frame = cell.Bounds;
    //shapeLayerBottom.BorderColor = VM.RedColor.ToNativeColor().CGColor;
    //shapeLayerBottom.BorderWidth = 3;
    shapeLayerBottom.Path = maskPathBottom.CGPath;

    //All Corners
    var maskPathAll = UIBezierPath.FromRoundedRect(cell.Bounds, UIRectCorner.BottomLeft | UIRectCorner.BottomRight | UIRectCorner.TopLeft | UIRectCorner.TopRight, new CoreGraphics.CGSize(8, 8));
    var shapeLayerAll = new CAShapeLayer();
    shapeLayerAll.Frame = cell.Bounds;
    //shapeLayerAll.BorderWidth = 3;
    //shapeLayerAll.BorderColor = VM.RedColor.ToNativeColor().CGColor;
    shapeLayerAll.Path = maskPathAll.CGPath;

    cell.Layer.Mask = shapeLayerAll;

    shadowView.AddSubview(cell);
    View.Add(shadowView);

}

请参阅:

谢谢!但这并没有在我的tableView中的部分周围提供阴影。更多信息,请参考我发布的截图。@Jack Hua-MSFTI上传了我的测试样本,请按照我的代码操作。您好,请查看我要求的截图[你所建议的对UIView很好,但对**表视图**中单独部分的阴影不起作用。@Jack Hua-MSFTYou节实际上是一个视图。所以把视图(单元格)放进去将阴影添加到您的分区中,您将获得它。谢谢:)但我正在使用u r实现为单元格的所有侧面添加阴影,这不符合我的要求。请参阅随附的屏幕截图()@Jack Hua-MSFT