我已经创建的UIView,我需要带圆角edges.I已经提供了边框颜色和宽度改变左上和左下角。 但边界为的UIView的圆矩形没有扩展到了边缘。
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);
你应该设置maskLayer的边框宽度和边框颜色 ,因为如果你把它们放在层视图将剪辑的边界。
请参阅下面的代码:
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);
文章来源: Border for rounded rectangle of UIView is not spreaded over the edges. Xamarin IOS