zoukankan      html  css  js  c++  java
  • Xamarin.iOS常用控件总结

    1.UIButton控件

    btn.SetTitle("test", UIControlState.Normal);

    UIControlState枚举类型使用:

    • Normal:默认可使用状态
    • Highlighted:当点击控件事件时控件的状态
    • Disabled:控件状态不可用
    • Selected:控件选中时的状态
    • Application: 使用Application的一个附加控件状态
    • Reserved:
    UIButton btn = UIButton.FromType(UIButtonType.System);

    UIButtonType枚举类型:

    • System
    • Custom
    • RoundedRect
    • DetailDisclosure
    • InfoLight
    • InfoDark
    • ContactAdd

    2.UIImageView

    UIImageView image = new UIImageView();
                image.Image = UIImage.FromFile("test.jpg");
                image.ContentMode = UIViewContentMode.Center;

    UIViewContentMode枚举类型:

    • ScaleToFill
    • ScaleAspectFit
    • ScaleAspectFill
    • Redraw
    • Center
    • Top,Bottom,Left,Rigth,TopLeft,TopRight,BottomLeft,BottomRight

    3.UITextView控件,显示和编辑文本

    base.ViewDidLoad();
                UIButton btn = new UIButton();
                UITextView myTextView = new UITextView();
                //....省略部分代码
                btn.Enabled = false;
                btn.TouchUpInside += (object sender, EventArgs e) =>
                {
                    myTextView.ResignFirstResponder();//隐藏键盘
                };
                myTextView.Delegate = new MyTextViewDelegate(this);
    private class MyTextViewDelegate : UITextViewDelegate
            {
    
                public MyTextViewDelegate (TextViewAppViewController parentController)
                {
                    this.parentController = parentController;
                }
                private TextViewAppViewController parentController;
    
                public override void EditingStarted (UITextView textView)
                {
                    this.parentController.btn.Enabled = true;
                }
    
                public override void EditingEnded (UITextView textView)
                {
                    this.parentController.btn.Enabled = false;
                }
    
                public override void Changed (UITextView textView)
                {
                    Console.WriteLine ("Text changed!");
                }
    
            }//end void MyTextViewDelegate

    4.UITextField控件,UIKeyboardType枚举类型,使用键盘

    private NSObject kbdWillShow, kbdDidHide;
            public override void ViewDidLoad()
            {
    
                base.ViewDidLoad();
                UITextField emailField = new UITextField();
                this.emailField.KeyboardType = UIKeyboardType.EmailAddress;
                this.emailField.ReturnKeyType = UIReturnKeyType.Done;
    
                // The Xamarin.iOS way.添加Observers,防止键盘阻挡输入框
                this.kbdWillShow = UIKeyboard.Notifications.ObserveWillShow((s, e) => {
    
                    RectangleF kbdBounds = e.FrameEnd;
                    RectangleF textFrame = this.emailField.Frame;
    
                    textFrame.Y -= kbdBounds.Height;
                    this.emailField.Frame = textFrame;
    
                });
    
                this.kbdDidHide = UIKeyboard.Notifications.ObserveDidHide((s, e) => {
    
                    RectangleF kbdBounds = e.FrameEnd;
                    RectangleF textFrame = this.emailField.Frame;
    
                    textFrame.Y += kbdBounds.Height;
                    this.emailField.Frame = textFrame;
    
                });
    
                // The "iOS-way".
    //            this.kbdWillShow = NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.WillShowNotification, delegate(NSNotification ntf) {
    //
    //                RectangleF kbdBounds = UIKeyboard.FrameEndFromNotification (ntf);
    //
    //                RectangleF textFrame = this.emailField.Frame;
    //
    //                textFrame.Y -= kbdBounds.Height;
    //                this.emailField.Frame = textFrame;
    //
    //            });
    
    //            this.kbdDidHide = NSNotificationCenter.DefaultCenter.AddObserver (UIKeyboard.DidHideNotification, delegate(NSNotification ntf) {
    //
    //                RectangleF kbdBounds = UIKeyboard.FrameEndFromNotification (ntf);
    //
    //                RectangleF textFrame = this.emailField.Frame;
    //
    //                textFrame.Y += kbdBounds.Height;
    //                this.emailField.Frame = textFrame;
    //
    //            } );
    
                this.emailField.ShouldReturn = delegate(UITextField textField) {
                    return textField.ResignFirstResponder ();
                };
    
            }
    NSNotificationCenter.DefaultCenter.RemoveObserver
    (this.kbdWillShow);
    NSNotificationCenter.DefaultCenter.RemoveObserver
    (this.kbdDidHide);

    5.UIProgressView控件

    this.buttonStartProgress.SetTitle ("Tap to start progress!", UIControlState.Normal);
                this.buttonStartProgress.TouchUpInside += delegate {
                    // Disable the button
                    this.buttonStartProgress.Enabled = false;
                    this.progressView.Progress = 0f;
                    // Start a progress
                    Task.Factory.StartNew(this.StartProgress);
                } ;
    
                // Initialize the progress view
                this.progressView = new UIProgressView (new RectangleF (60f, 200f, 200f, 50f));            
    
                // Set the progress view's initial value
                this.progressView.Progress = 0f;
    
                // Set the progress increment value
                // for 10 items
                this.incrementBy = 1f / 10f;
    
                // Display the controls
                this.View.AddSubview(this.labelStatus);
                this.View.AddSubview(this.buttonStartProgress);
                this.View.AddSubview(this.progressView);
    private void StartProgress ()
            {
    
                float currentProgress = 0f;
                while (currentProgress < 1f)
                {
    
                    Thread.Sleep(1000);
    
                    this.InvokeOnMainThread(delegate {
    
                        // Advance the progress
                        this.progressView.Progress += this.incrementBy;
                        currentProgress = this.progressView.Progress;
    
                        // Set the label text
                        this.labelStatus.Text = string.Format("Current value: {0}", Math.Round((double)this.progressView.Progress, 2));
    
                        if (currentProgress >= 1f)
                        {
                            this.labelStatus.Text = "Progress completed!";
                            this.buttonStartProgress.Enabled = true;
                        }//end if
    
                    });
    
                }//end while

    6.UIScrollView控件

    常用属性:

    • ContentSize
    • ContentOffset
    • PagingEnabled

    常用事件:

    • Scrolled
    • DecelerationStarted
    • DecelerationEnded
  • 相关阅读:
    基于K-means聚类算法的图像分割 和 基于机器学习的图像二元分类
    .off文件三维数据读取并显示
    滑动窗口&Region Proposal&Selective Search&KMeans&二元分类(空间分割)
    ENVI+IDL遥感图像处理
    OpenCV与图像分割 边界检测
    SublimeText3追踪函数工具CTags设置及使用
    岗位要求
    bash shell脚本如何获取脚本所在目录
    mongodb获取到的可能已经沦为肉鸡的云服务器地址
    wireshark查看包显示:Packet size limitedduring capture
  • 原文地址:https://www.cnblogs.com/zjmsky/p/4975975.html
Copyright © 2011-2022 走看看