UIView的圆角矩形的边框不会散布在边缘上。 Xamarin IOS

时间:2019-03-21 07:11:42

标签: swift xamarin.ios

我已经创建了UIView,我需要用圆角边缘更改topleft和bottom bottom.I提供了边框的颜色和宽度。但是该UIView的更圆角矩形的Border不会散布在边缘。

     view.Frame = new CGRect(0, 0,36,36);
        var maskLayer = new CAShapeLayer();
        maskLayer.Path = UIBezierPath.FromRoundedRect(view.Bounds, (UIRectCorner.TopLeft | UIRectCorner.BottomLeft), new CoreGraphics.CGSize(36.0,36.0)).CGPath;
        maskLayer.Bounds = m_scrollHead.Frame;


        view.Layer.Mask = maskLayer;

        view.Layer.BorderWidth = 1;
        view.Layer.BorderColor = new CoreGraphics.CGColor(0, 0, 0);

1 个答案:

答案 0 :(得分:0)

您应该在 maskLayer 上设置 BorderWidth BorderColor ,因为如果将它们设置在图层上,则视图将剪切边框。

请参考以下代码:

UIView view = new UIView();
view.BackgroundColor = UIColor.Clear;
view.Frame = new CGRect(30, 100, 36, 36);
var maskLayer = new CAShapeLayer();

UIBezierPath bezierPath = UIBezierPath.FromRoundedRect(view.Bounds, (UIRectCorner.TopLeft | UIRectCorner.BottomLeft), new CGSize(18.0, 18.0));


maskLayer.Path = bezierPath.CGPath;
maskLayer.Frame = view.Bounds;

maskLayer.StrokeColor = UIColor.Black.CGColor; //set the borderColor
maskLayer.FillColor = UIColor.Red.CGColor;   //set the background color
maskLayer.LineWidth = 1;  //set the border width

view.Layer.AddSublayer(maskLayer);

View.AddSubview(view);

enter image description here