Picker in Xamarin.iOS available

后端 未结 3 1094
清歌不尽
清歌不尽 2020-12-11 05:03

Is iOS Picker available in the Xamarin.iOS? I have searched throughly but there is neither example nor information has been founded; however, it is available in Xamarin.Form

3条回答
  •  旧时难觅i
    2020-12-11 05:49

    A real quickie example of a UIPickerView: (iOS SDK)

    Add a UIPickerView to your xib or Storyboard called slotMachineView:

    using System;
    using UIKit;
    
    namespace Slots
    {
        public partial class ViewController : UIViewController
        {
            public ViewController (IntPtr handle) : base (handle)
            {
            }
    
            public override void ViewDidLoad ()
            {
                base.ViewDidLoad ();
                    slotMachineView.Model = new StackOverflowModel (selectedLbl);
            }
    
            public override void DidReceiveMemoryWarning ()
            {
                base.DidReceiveMemoryWarning ();
            }
        }
    
        public class StackOverflowModel : UIPickerViewModel
        {
            static string[] names = new string [] {
                "pscorlib.dll",
                "pscorlib_aot.dll",
                "Mono.PlayScript.dll",
                "PlayScript.Dynamic.dll",
                "PlayScript.Dynamic_aot.dll",
                "PlayScript.Optimization.dll",
                "playshell.exe",
                "psc.exe"
            };
    
            UILabel lbl;
    
            public StackOverflowModel (UILabel lbl)
            {
                this.lbl = lbl;
            }
    
            public override nint GetComponentCount (UIPickerView v)
            {
                return 3;
            }
    
            public override nint GetRowsInComponent (UIPickerView pickerView, nint component)
            {
                return names.Length;
            }
    
            public override string GetTitle (UIPickerView picker, nint row, nint component)
            {
                switch (component) {
                case 0:
                    return names [row];
                case 1:
                    return row.ToString ();
                case 2:
                    return new string ((char)('A' + row), 1);
                default:
                    throw new NotImplementedException ();
                }
            }
    
            public override void Selected (UIPickerView picker, nint row, nint component)
            {
                lbl.Text = String.Format ("{0} : {1} : {2}",
                    names [picker.SelectedRowInComponent (0)],
                    picker.SelectedRowInComponent (1),
                    picker.SelectedRowInComponent (2));
            }
    
            public override nfloat GetComponentWidth (UIPickerView picker, nint component)
            {
                if (component == 0)
                    return 220f;
                else
                    return 30f;
            }
        }
    }
    

提交回复
热议问题