Mc-*_*Mc- 1 graphics uiview xamarin.ios ios
我想创建自己的自定义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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1726 次 |
| 最近记录: |