我想创建自己的自定义UIView,因为应用程序上的所有屏幕都将以编程方式创建背景。
问题是,我应该在哪里覆盖drawRect方法?
一方面,在IB端将其设置为有意义,因为这样,我可以直接在Identity Inspector 中将新创建的类UICustomView分配为。
另一方面,我是Monotouch的新手,但似乎所有逻辑都应放在C#上。
我都尝试在两者中都这样做:),但似乎没有任何作用
您能指出我一些教程还是给我一些建议,以了解哪种是重写Monotouch中的UIVIew类的最佳方法?
最佳答案
我在这里找到了解决方案:
http://lists.ximian.com/pipermail/monotouch/2009-September/000599.html
这是示例代码:
using System;
using MonoTouch.CoreGraphics;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace LongoMatch
{
public partial class UICustomView : UIView
{
public UICustomView(IntPtr handle) : base(handle)
{
}
public override void Draw (RectangleF rect)
{
MonoTouch.CoreGraphics.CGContext context = UIGraphics.GetCurrentContext();
context.SetLineWidth(8.0f);
context.SetStrokeColor(new CGColor(0f, 0f, 0f));
context.MoveTo(10,10);
context.AddLines(new PointF[] { new PointF(60, 60), new PointF(100, 100) });
context.StrokePath();
SetNeedsDisplay();
}
}
}
关于ios - Monotouch自定义UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8375524/