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
时间: 2024-12-16 07:29:15

Xamarin.iOS常用控件总结的相关文章

iOS常用控件尺寸大集合

元素控件 尺寸(pts) Window(含状态栏) 320 x 480 Status Bar的高度 20 Navigation Bar的高度 44 含Prompt的Navigation Bar的高度 74 Navigation Bar的图标 20×20(透明的png) Tool Bar的高度 44 Tool Bar的图标 20×20(透明的png) Tab Bar的高度 49 Tab Bar的图标 30×30(透明的png) 竖直时键盘的高度 216.252(iOS 5+的中文键盘) 水平时键盘

iOS 常用控件的方法属性总结

一 UIVIew 常见属性1.frame 位置和尺寸(以父控件的左上角为原点(0,0))2.center 中点 (以父控件的左上角为原点(0,0))3.bounds 位置和尺寸(以自己的左上角为原点 (0,0))4.transform 形变属性(缩放,旋转)5.backgroundColor 背景颜色6.tag 标识(父控件可以根据这个标识找到对应的子控件,同一个父控件中的子控件不要一样)7. hidden 设置是否要隐藏8.alpha 透明度(0~1);9.opaque 不透明度(0~1);1

Xamarin.ios 基本控件

1// 1.按钮 UIButton 2 UIButton btn = new UIButton(); 3 btn.Frame = new RectangleF(150,310,80,30); //按钮位置一件宽高 4 btn.SetTitle("Button",UIControlState.Normal); //显示的文字 5 btn.SetTitleColor(UIColor.Black,UIControlState.Normal);//文字的颜色 6 btn.TouchUpInsi

iOS常用控件-UIScrollView

一. 常见属性 @property (nonatomic) CGPoint contentOffset;                      //记录UIScrollView滚动的位置 @property (nonatomic) CGSize contentSize;                          // 内容尺寸 (能滚动的范围) @property (nonatomic) UIEdgeInsets contentInset;                // 额外增

iOS常用控件-UITableViewCell

一. 封装cell: 1.加载xib文件的两种方式 <方式1> (NewsCell是xib文件的名称) NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:nil options:nil]; <方式2> UINib *nib = [UINib nibWithNibNamed:@"NewsCell" bundle:nil]; NSArry *objec

iOS 常用控件集合 完整项目

[Swift]高仿 爱范儿3.0 http://www.code4app.com/forum.php?mod=viewthread&tid=10053&page=1&extra=#pid220850 登陆界面+转场结合设计UI地址 http://www.code4app.com/forum.php?mod=viewthread&tid=10024&extra=page%3D1%26filter%3Dsortid%26sortid%3D1 一个基于React Nati

IOS 常用控件的使用

UIButton  //初始化 位置  UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(self.view.frame.size.width-180, 45, 80, 30)];     [btn.layer setCornerRadius:5.0]; //设置矩形四个圆角半径     [btn.layer setBorderWidth:1.0]; //边框宽度     CGColorSpaceRef colorSpace =

iOS常用控件默认高度

参考网址http://www.2cto.com/kf/201307/228020.html

IOS开发基础常用控件简介

在IOS开发中,各类控件完美的解决了开发过程中界面与交互展现的问题,使得IOS产品界面更加灵活实用,IOS常用控件的介绍如下. 1.窗口 UIWindow iPhone的规则是一个窗口,多个视图,窗口是你在app显示出来你看到的最底层,他是固定不变的,基本上可以不怎么理会,但要知道每层是怎样的架构. 2.视图 UIView, 是用户构建界面的基础,所有的控件都是在这个页面上画出来的,你可以把它当成是一个画布,你可以通过UIView增加控件,并利用控件和用户进行交互和传递数据. 窗口和视图是最基本