如何在带有 Monotouch 的 XIB 编辑器中使用自定义 UIView 子类?
我已将基于 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的视图子类至少需要两件事:
注册属性
[注册("MyView")]
public class MyView : UIView {}
IntPtr 构造函数
public MyView(IntPtr handle) : base(handle) {}
然后在 Interface Builder 中打开 XIB,添加 UIView 并将其在 Identity Inspector 中的 Class 设置为您传递给 Register 属性的名称。当您将其连接到插座时,您会看到它具有正确的类型。
Your view subclass needs at least two things:
Register attribute
[Register("MyView")]
public class MyView : UIView {}
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.