CGPath?GetRoundedPath(CGRect rect, nfloat left, nfloat top, nfloat right, nfloat bottom) { #if __IOS__ var path = new UIBezierPath(); #else var path = new NSBezierPath(); #endif path.MoveTo(new CGPoint(rect.Width - right, rect.Y)); path.AddArc(new CGPoint((float)rect.X + rect.Width - right, (float)rect.Y + right), (nfloat)right, (float)(Math.PI * 1.5), (float)Math.PI * 2, true); path.AddLineTo(new CGPoint(rect.Width, rect.Height - bottom)); path.AddArc(new CGPoint((float)rect.X + rect.Width - bottom, (float)rect.Y + rect.Height - bottom), (nfloat)bottom, 0, (float)(Math.PI * .5), true); path.AddLineTo(new CGPoint(left, rect.Height)); path.AddArc(new CGPoint((float)rect.X + left, (float)rect.Y + rect.Height - left), (nfloat)left, (float)(Math.PI * .5), (float)Math.PI, true); path.AddLineTo(new CGPoint(rect.X, top)); path.AddArc(new CGPoint((float)rect.X + top, (float)rect.Y + top), (nfloat)top, (float)Math.PI, (float)(Math.PI * 1.5), true); path.ClosePath(); #if __IOS__ return(path.CGPath); #else return(path.ToCGPath()); #endif }
public static NSBezierPath CreateRoundedRectPath(this CGRect rect, CornerRadius cornerRadius) { var path = new NSBezierPath(); path.MoveTo(new CGPoint(rect.Width - cornerRadius.TopRight, rect.Y)); path.AddArc(new CGPoint((float)rect.X + rect.Width - cornerRadius.TopRight, (float)rect.Y + cornerRadius.TopRight), (nfloat)cornerRadius.TopRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true); path.AddLineTo(new CGPoint(rect.Width, rect.Height - cornerRadius.BottomRight)); path.AddArc(new CGPoint((float)rect.X + rect.Width - cornerRadius.BottomRight, (float)rect.Y + rect.Height - cornerRadius.BottomRight), (nfloat)cornerRadius.BottomRight, 0, (float)(Math.PI * .5), true); path.AddLineTo(new CGPoint(cornerRadius.BottomLeft, rect.Height)); path.AddArc(new CGPoint((float)rect.X + cornerRadius.BottomLeft, (float)rect.Y + rect.Height - cornerRadius.BottomLeft), (nfloat)cornerRadius.BottomLeft, (float)(Math.PI * .5), (float)Math.PI, true); path.AddLineTo(new CGPoint(rect.X, cornerRadius.TopLeft)); path.AddArc(new CGPoint((float)rect.X + cornerRadius.TopLeft, (float)rect.Y + cornerRadius.TopLeft), (nfloat)cornerRadius.TopLeft, (float)Math.PI, (float)(Math.PI * 1.5), true); path.ClosePath(); return(path); }