mono touch中UISwitch控件的使用

有不明白的地方欢迎入群  347636249  探讨
using System;
//
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Drawing;

namespace GCForum
{
	public class MyTestVC :UIViewController
	{
		public MyTestVC ()
		{
		}

		private UISwitch _switch;
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			this.View.BackgroundColor = UIColor.White;

			UILabel lbl = xxxx.ControlCenter.CreateLbl (new RectangleF (10, 100, 100, 20), "");
			this.View.Add (lbl);

			_switch = new UISwitch {
				BackgroundColor = UIColor.Red,
				Frame = new RectangleF (new PointF(10,10),SizeF.Empty)
			};
			_switch.SetState (true, false); //默认设置on选项
			_switch.ValueChanged += delegate {
				lbl.Text=_switch.On.ToString();
			};
			this.View.Add (_switch);
		}

		//...

	}
}

关键是ValueChanged方法,另外,虽然说UISwitch是继承于UIControl,但它的大小是固定的,你即便设置了它的大小,显示不会有变化。

mono touch中UISwitch控件的使用_第1张图片

你可能感兴趣的:(UISwitch,ValueChanged)