繁体   English   中英

你怎么能在Xamarin.iOS UITableView上只绕过2个角?

[英]How can you round only 2 of the corners on a Xamarin.iOS UITableView?

我正在使用当前版本的Xamarin.iOS和C#开发一个iPad应用程序,我正在尝试创建一个只有两个角(右上角和右下角)四舍五入的UITableView 我知道如何通过设置myTable.Layer.CornerRadius = 6f;舍入所有角落myTable.Layer.CornerRadius = 6f; 但不知道如何只围绕其中两个。 我环顾四周,但只能看到Objective-C的答案。 这就是我目前所拥有的:

    private UIView GetModalRowHeaderView2(RectangleF bounds)
    {
        UIView view = new UIView(bounds);
        view.BackgroundColor = UIColor.Gray;

        string[] tableItems = new string[] {"Item One","Item Two","Item Three"};

        UITableView myTable = new UITableView(new RectangleF(0, 20, bounds.Width, bounds.Height - 40), UITableViewStyle.Plain);
        myTable.SeparatorInset = UIEdgeInsets.Zero;
        myTable.ScrollEnabled = false;
        myTable.Source = new TableSource(tableItems);

        // Rounds all corners
        myTable.Layer.CornerRadius = 6f;

        view.Add(myTable);

        return view;
    }

任何想法我怎么能改变这只到圆角的两个角落?

谢谢,

您需要使用遮罩层。 在我的Github回购中,我有一个带有圆角矩形视图的 Xamarin.iOS代码。 您可以将此作为开始。

摘自代码:

UIBezierPath maskPath = UIBezierPath.FromRoundedRect (this.Bounds, this.eRoundedCorners, new SizeF (this.fCornerRadius, this.fCornerRadius));

CAShapeLayer maskLayer = new CAShapeLayer ();
maskLayer.Frame = this.Bounds;
maskLayer.Path = maskPath.CGPath;

// Set the newly created shape layer as the mask for the image view's layer
this.Layer.Mask = maskLayer;

从iOS 11开始,有一个新属性叫做:

例如3给我两个顶角圆

view.Layer.MaskedCorners = (CoreAnimation.CACornerMask)3;
view.Layer.CornerRadius = 15f;
  • 0:没有圆角
  • 1:左上角
  • 2:右上角
  • 3:左上角和右上角(两个顶角)
  • 4:左下角
  • 5:左上角和左下角(左角)
  • 6:右上角和左下角
  • 7:左上角和右上角,左下角(除了右下角以外的所有角落)
  • 8:右下角
  • 9:左上角,右下角
  • 10:右上角和右下角(右角)
  • 11:两个顶角,右下角(除了左下角以外的所有角落)
  • 12:左下和右下(两个底角)
  • 13:左下和右下,左上角(除了右上角以外的所有角落)
  • 14:左下和右下,右上(除了左上角以外的所有角落)
  • 15:所有角落圆润

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM