如何在Monotouch的XIB编辑器中使用自定义UIView子类? [英] How to use custom UIView subclass in XIB editor with Monotouch?

查看:106
本文介绍了如何在Monotouch的XIB编辑器中使用自定义UIView子类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

(I'm using Xcode 4.2 and MD 2.8.6.4)

推荐答案

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

Your view subclass needs at least two things:


  1. 注册属性

  1. Register attribute

[注册(MyView)]

公共类MyView:UIView {}

IntPtr构造函数

IntPtr constructor

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

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

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.

这篇关于如何在Monotouch的XIB编辑器中使用自定义UIView子类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆