2016-04-01 10 views
0

私のXamarin.iOSアプリケーションには、同じスキームを持つが、standart UIButtonとは異なるボタンがたくさんあります。ほとんどの機能は同じですが、たとえば、テキストの色や背景の色が異なるため、ボタンのクラスを1つ作成しました。Xamarin.iOS:追加のオブジェクトを含むカスタムボタンを作成

どのようにしてストーリーボードのボタンについての追加情報を入力できますか? そして、私はどのようにコードに反応できますか?

答えて

2

あなたはDesignTimeVisibleとデザイナー、あなたはあなただけExportBrowsable (true)を追加するHAE Designerで設定したいすべてのプロパティのために

[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; 
    } 
} 

ようRegister属性のためのあなたのカスタム要素が見えるようにすることができます。 Initializeでは、共通プロパティのすべての値を設定できます。

ツールボックスのCustom Componentsに表示されます。再構築する必要があるかもしれません。 enter image description here

とカスタムプロパティ はPropertiesペインで変更することができ

enter image description here

さらに詳しい情報:https://developer.xamarin.com/guides/ios/user_interface/designer/ios_designable_controls_overview/

関連する問題