我想绘制一个带圆角的矩形,但我对平台并不熟悉,它与WPF或UWP非常不同。
我在Objective-C中看过一些例子,但我不知道如何翻译成Xamarin.iOS。
答案 0 :(得分:2)
圆角填充矩形路径:
var rectanglePath = UIBezierPath.FromRoundedRect(new CGRect(0.0f, 0.0f, 200.0f, 100.0f), 50.0f);
UIColor.Red.SetFill();
rectanglePath.Fill();
UIGraphics.BeginImageContext(new CGSize(200.0f, 100.0f));
var rectanglePath = UIBezierPath.FromRoundedRect(new CGRect(0.0f, 0.0f, 200.0f, 100.0f), 50.0f);
UIColor.Red.SetFill();
rectanglePath.Fill();
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
public class RoundedBox : UIView
{
public RoundedBox()
{
}
public RoundedBox(Foundation.NSCoder coder) : base(coder)
{
}
public RoundedBox(Foundation.NSObjectFlag t) : base(t)
{
}
public RoundedBox(IntPtr handle) : base(handle)
{
}
public RoundedBox(CoreGraphics.CGRect frame) : base(frame)
{
}
public override void Draw(CGRect rect)
{
var rectanglePath = UIBezierPath.FromRoundedRect(rect, 50.0f);
UIColor.Red.SetFill();
rectanglePath.Fill();
}
}