如何在带有 Monotouch 的 XIB 编辑器中使用自定义 UIView 子类?

发布于 2025-01-07 02:27:58 字数 374 浏览 6 评论 0原文

我已将基于 XIB 的 UIViewController 添加到我的解决方案中,并将一些 UIViews 拖入其中。 现在我希望一些视图不是 UIView 而是 RoundedRectView (https://github.com/Krumelur/RoundedRectView) 继承自 UIView

如何实现这一目标?我尝试更改 Interface Builder 中的类,但没有任何作用。然后我手动修改了designer.cs文件,但导致失败。 然后我尝试修改假的 ObjC 代码,但也失败了。

(我使用的是 Xcode 4.2 和 MD 2.8.6.4)

I have added a XIB based UIViewController to my solution and dragged some UIViews into it.
Now I want some of the views not to be UIView but RoundedRectView
(https://github.com/Krumelur/RoundedRectView) which inherits from UIView.

How to achieve this? I tried to change the class in Interface Builder but that did nothing. Then I manually modified the designer.cs file but that resulted in a failure.
Then I tried modifying the fake ObjC code but that failed too.

(I'm using Xcode 4.2 and MD 2.8.6.4)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南城旧梦 2025-01-14 02:27:58

您的视图子类至少需要两件事:

  1. 注册属性

    [注册("MyView")]

    public class MyView : UIView {}

  2. IntPtr 构造函数

    public MyView(IntPtr handle) : base(handle) {}

然后在 Interface Builder 中打开 XIB,添加 UIView 并将其在 Identity Inspector 中的 Class 设置为您传递给 Register 属性的名称。当您将其连接到插座时,您会看到它具有正确的类型。

类型正确的插座

Your view subclass needs at least two things:

  1. Register attribute

    [Register("MyView")]

    public class MyView : UIView {}

  2. IntPtr constructor

    public MyView(IntPtr handle) : base(handle) {}

You then open the XIB in Interface Builder, add a UIView and set its Class in the Identity Inspector to the name you passed to the Register attribute. When you connect it to an outlet, you will see that it has the correct type.

Outlet with correct type

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文