在 MonoTouch 中我定义了以下类:
using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Drawing;
namespace MyApp
{
public class WUILabel : UILabel
{
public WUILabel () : base() { this.SetDefaults(); }
public WUILabel(NSCoder coder) : base(coder) { this.SetDefaults(); }
public WUILabel(NSObjectFlag t) : base(t) { this.SetDefaults(); }
public WUILabel(IntPtr handle) : base(handle) { this.SetDefaults(); }
public WUILabel(RectangleF frame) : base(frame) { this.SetDefaults(); }
private void SetDefaults()
{
this.Font = UIFont.FromName("AmericanTypewriter", 15f);
this.TextColor = UIColor.Black;
}
}
}
在 Interface Builder 中,我将标签的“Class”属性设置为“WUILabel”。
当我运行应用程序时,应用程序输出包含错误“Interface Builder 文件中存在未知类 WUILabel”。有没有人成功地让它发挥作用,或者有人可以告诉我我做错了什么吗?
最佳答案
您必须使用 RegisterAttribute 来装饰您的类。
检查this回答。
关于xamarin.ios - Interface Builder 看不到我的子类 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11271080/