标签:
1.UIButton控件
btn.SetTitle("test", UIControlState.Normal);
UIControlState枚举类型使用:
UIButton btn = UIButton.FromType(UIButtonType.System);
UIButtonType枚举类型:
2.UIImageView
UIImageView image = new UIImageView(); image.Image = UIImage.FromFile("test.jpg"); image.ContentMode = UIViewContentMode.Center;
UIViewContentMode枚举类型:
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控件
常用属性:
常用事件:
标签:
原文地址:http://www.cnblogs.com/zjmsky/p/4975975.html