ios - Monotouch自定义UIView

标签 ios graphics uiview xamarin.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();
        }


    }
}

关于ios - Monotouch自定义UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8375524/

相关文章:

ios - 从循环更新 View

delphi - TPaintBox 到 JPEG/BMP - 缓冲区

iOS白色到透明渐变层为灰色

ios - 如何使 UILabel 出现和消失 5 次?

ios - 横屏模式下的 Swift SpriteKit iAd

ios - Xcode 6.3 找不到 watchkit 扩展 swift 文件

ios - Flutter 点击手势不适用于 UiKitView 和 MapBox

Java - 在图像的中心绘制文本

user-interface - GUI 输出如何从应用程序到硬件级别工作?

ios - 在 View 中播放多个视频的最佳方式是什么?