Xamarin.iOS:使用附加对象创建自定义按钮
在我的Xamarin.iOS应用程序中,有许多按钮具有相同的方案,但与标准UIButton不同。我为按钮创建了一个类,因为大多数功能是相同的,但例如textcolor或backgroundcolor是不同的 那么,我如何在故事板中添加关于任何按钮的额外信息呢?Xamarin.iOS:使用附加对象创建自定义按钮,ios,xamarin,xamarin.ios,storyboard,Ios,Xamarin,Xamarin.ios,Storyboard,在我的Xamarin.iOS应用程序中,有许多按钮具有相同的方案,但与标准UIButton不同。我为按钮创建了一个类,因为大多数功能是相同的,但例如textcolor或backgroundcolor是不同的 那么,我如何在故事板中添加关于任何按钮的额外信息呢? 如何在代码中对其作出反应?您可以使用DesignTimeVisible和Register属性使自定义元素在中对设计器可见,如 [Register ("CustomButton"), DesignTimeVisible (true)] pu
如何在代码中对其作出反应?您可以使用
DesignTimeVisible
和Register
属性使自定义元素在中对设计器可见,如
[Register ("CustomButton"), DesignTimeVisible (true)]
public class CustomButton: UIButton {
[Export ("CustomProperty "), Browsable (true)]
public int CustomProperty {get; set;}
public CustomButton(IntPtr handle) : base (handle) { }
public CustomButton()
{
// Called when created from code.
Initialize ();
}
public override void AwakeFromNib ()
{
// Called when loaded from xib or storyboard.
Initialize ();
}
void Initialize ()
{
// Common initialization code here.
CustomProperty = 0xB00B5;
}
}
对于要在设计器中设置的所有属性,只需添加Export
和Browsable(true)
。在Initialize
中,可以设置公共属性的所有值
它将出现在工具箱中的自定义组件下。你可能需要重建。
并且可以在属性
窗格中修改自定义属性
更多信息:您可以使用
DesignTimeVisible
和Register
属性使自定义元素在中对设计器可见,如
[Register ("CustomButton"), DesignTimeVisible (true)]
public class CustomButton: UIButton {
[Export ("CustomProperty "), Browsable (true)]
public int CustomProperty {get; set;}
public CustomButton(IntPtr handle) : base (handle) { }
public CustomButton()
{
// Called when created from code.
Initialize ();
}
public override void AwakeFromNib ()
{
// Called when loaded from xib or storyboard.
Initialize ();
}
void Initialize ()
{
// Common initialization code here.
CustomProperty = 0xB00B5;
}
}
对于要在设计器中设置的所有属性,只需添加Export
和Browsable(true)
。在Initialize
中,可以设置公共属性的所有值
它将出现在工具箱中的自定义组件下。你可能需要重建。
并且可以在属性
窗格中修改自定义属性
更多信息: