「Xamarin.iOSでダイアログを表示する」の版間の差分

提供:MonoBook
imported>Administrator
編集の要約なし
Administrator がページ「Xamarin.iOS/ダイアログを表示する」を「Xamarin.iOSでダイアログを表示する」に移動しました
 
(他の1人の利用者による、間の2版が非表示)
3行目: 3行目:
iOS8以降ではUIAlertControllerを使えとのこと。
iOS8以降ではUIAlertControllerを使えとのこと。
<source lang="csharp">
<source lang="csharp">
            var alert = UIAlertController.Create("title", "message", UIAlertControllerStyle.Alert);
    var alert = UIAlertController.Create("title", "message", UIAlertControllerStyle.Alert);


            alert.AddAction(UIAlertAction.Create("NO", UIAlertActionStyle.Cancel , (handler) => {
    alert.AddAction(UIAlertAction.Create("NO", UIAlertActionStyle.Cancel , (handler) => {
                Console.WriteLine("NO");
        Console.WriteLine("NO");
            }));
    }));


            alert.AddAction(UIAlertAction.Create("YES", UIAlertActionStyle.Default, (handler) => {
    alert.AddAction(UIAlertAction.Create("YES", UIAlertActionStyle.Default, (handler) => {
                Console.WriteLine("YES: " + alert.TextFields[0].Text);
        Console.WriteLine("YES: " + alert.TextFields[0].Text);
            }));
    }));


            alert.AddTextField((textfield) => {
    alert.AddTextField((textfield) => {
                textfield.Placeholder = "textfield";
        textfield.Placeholder = "textfield";


                //
        //
                var label = new UILabel(new CGRect(0, 0, 80, 30));
        var label = new UILabel(new CGRect(0, 0, 80, 30));
                label.Text = "LABEL: ";
        label.Text = "LABEL: ";


                textfield.LeftView = label;
        textfield.LeftView = label;
                textfield.LeftViewMode = UITextFieldViewMode.Always;
        textfield.LeftViewMode = UITextFieldViewMode.Always;
            });
    });


            this.PresentViewController(alert, animated: true, completionHandler: null);
    this.PresentViewController(alert, animated: true, completionHandler: null);
</source>
</source>



2020年12月23日 (水) 03:07時点における最新版

iOS 8以降[編集 | ソースを編集]

iOS8以降ではUIAlertControllerを使えとのこと。

    var alert = UIAlertController.Create("title", "message", UIAlertControllerStyle.Alert);

    alert.AddAction(UIAlertAction.Create("NO", UIAlertActionStyle.Cancel , (handler) => {
        Console.WriteLine("NO");
    }));

    alert.AddAction(UIAlertAction.Create("YES", UIAlertActionStyle.Default, (handler) => {
        Console.WriteLine("YES: " + alert.TextFields[0].Text);
    }));

    alert.AddTextField((textfield) => {
        textfield.Placeholder = "textfield";

        //
        var label = new UILabel(new CGRect(0, 0, 80, 30));
        label.Text = "LABEL: ";

        textfield.LeftView = label;
        textfield.LeftViewMode = UITextFieldViewMode.Always;
    });

    this.PresentViewController(alert, animated: true, completionHandler: null);

ボタンのフォントを以下の3つの中から選ぶことができる。

  • UIAlertActionStyle.Default:標準
  • UIAlertActionStyle.Cancel:Bold表示
  • UIAlertActionStyle.Destructive:文字色が赤色

関連項目[編集 | ソースを編集]

参考文献[編集 | ソースを編集]