UIView 圆角矩形的边框没有分布在边缘上.Xamarin IOS [英] Border for rounded rectangle of UIView is not spreaded over the edges. Xamarin IOS

查看:29
本文介绍了UIView 圆角矩形的边框没有分布在边缘上.Xamarin IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了 UIView ,我需要用圆形边缘更改左上角和左下角.我提供了边框颜色和宽度.但是该 UIView 的圆角矩形的边框没有分布在边缘上.

I have Created UIView , I need to change topleft and Bottom Left with rounded edges.I have provided with border color and width. But Border for rounder rectangle of that UIView is not spreaded over the edges.

     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);

推荐答案

你应该在 ma​​skLayer 上设置 BorderWidthBorderColor 因为视图如果将它们设置在图层上,则会裁剪边框.

You should set the BorderWidth and BorderColor on maskLayer because the view will clip the border if you set them on layer.

参考以下代码:

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);

这篇关于UIView 圆角矩形的边框没有分布在边缘上.Xamarin IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆