UIView.Draw(CGRect) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在传入的矩形内绘制视图。
[Foundation.Export("drawRect:")]
[ObjCRuntime.ThreadSafe]
public virtual void Draw (CoreGraphics.CGRect rect);
abstract member Draw : CoreGraphics.CGRect -> unit
override this.Draw : CoreGraphics.CGRect -> unit
参数
- rect
- CGRect
要绘制的 RectangleF。
- 属性
注解
Draw(CGRect)绝不应直接调用 方法。 它在运行循环处理期间由 iOS 调用。 第一次通过运行循环时,将调用它。 之后,只要视图被标记为需要显示,就会通过调用 SetNeedsDisplayInRect(CGRect) 或 SetNeedsDisplayInRect(CGRect)按需调用它。
核心图形使用与设备无关的点,而不是像素。 这样,绘图代码就可以在不同的分辨率之间进行缩放。 例如,在 Retina 显示器上,1 磅相当于 2 像素,而在非 Retina 显示器上,1 磅相当于 1 像素。
public override void Draw (RectangleF rect)
{
base.Draw (rect);
var context = UIGraphics.GetCurrentContext ();
context.SetLineWidth(4);
UIColor.Red.SetFill ();
UIColor.Blue.SetStroke ();
var path = new CGPath ();
path.AddLines(new PointF[]{
new PointF(100,200),
new PointF(160,100),
new PointF(220,200)});
path.CloseSubpath();
context.AddPath(path);
context.DrawPath(CGPathDrawingMode.FillStroke);
}
这可以从后台线程使用。