【发布时间】:2017-06-10 18:43:17
【问题描述】:
我想绘制一个带圆角的矩形,但我对这个平台很陌生,它与例如 WPF 或 UWP 确实不同。
我看过 Objective-C 中的示例,但我不知道如何翻译成 Xamarin.iOS。
【问题讨论】:
标签: c# .net xamarin xamarin.ios drawing
我想绘制一个带圆角的矩形,但我对这个平台很陌生,它与例如 WPF 或 UWP 确实不同。
我看过 Objective-C 中的示例,但我不知道如何翻译成 Xamarin.iOS。
【问题讨论】:
标签: c# .net xamarin xamarin.ios drawing
圆角填充矩形路径:
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();
}
}
【讨论】: