【发布时间】:2016-04-01 20:25:36
【问题描述】:
在我的 Xamarin.iOS 应用程序中,有许多按钮具有相同的方案,但与标准 UIButton 不同。我为按钮创建了一个类,因为大多数功能是相同的,但例如 textcolor 或 backgroundcolor 是不同的。
那么我怎样才能在情节提要中添加有关任何按钮的额外信息? 我如何在代码中对此做出反应?
【问题讨论】:
标签: ios xamarin xamarin.ios storyboard
在我的 Xamarin.iOS 应用程序中,有许多按钮具有相同的方案,但与标准 UIButton 不同。我为按钮创建了一个类,因为大多数功能是相同的,但例如 textcolor 或 backgroundcolor 是不同的。
那么我怎样才能在情节提要中添加有关任何按钮的额外信息? 我如何在代码中对此做出反应?
【问题讨论】:
标签: ios xamarin xamarin.ios storyboard
您可以使用 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你可以设置所有常用属性的值。
它将出现在Custom Components 下的工具箱中。你可能不得不重建。
并且可以在Properties 窗格中修改自定义属性
更多信息:https://developer.xamarin.com/guides/ios/user_interface/designer/ios_designable_controls_overview/
【讨论】: