想学用C#开发iphone 的就加入 QQ群:178290571 ,让我们共同进步吧!
C# MonoTouch for iphone 开发blog http://blog.csdn.net/ssihc0/
MonoDevelop 版本:2.8.0
MonoTouch 版本:4.2.2
UIButton 不用多说,,和我们在windows button 一样,只是在iso 里它漂亮多了
Title 显示的文本。
Image 按钮上显示的图片。
Background 用作按钮背景的图片。
TextColor 指定文本颜色。
Shadow 阴影 指定特定的颜色。
UIButtonType
Custom, 没有按钮样式,
RoundedRect, 带有圆角和居中标题的矩形按钮。用手所有通用按钮。
DetailDisclosure, 还有居中燕尾形(>)的圆形按钮。
InfoLight,
InfoDark,
ContactAdd
下面是方法和属性:
UIButton 经常用到 TouchUpInside 事件,,,当手按下,抬起的时候触发TouchUpInside事件
新建一个工程名为Button 打开ButtonViewController
添加下面代码
private UILabel label1; public ButtonViewController (string nibName, NSBundle bundle) : base (nibName, bundle) { } public override void DidReceiveMemoryWarning () { // Releases the view if it doesn't have a superview. base.DidReceiveMemoryWarning (); // Release any cached data, images, etc that aren't in use. } public override void ViewDidLoad () { base.ViewDidLoad (); label1= new UILabel(); label1.Text= "click"; label1.Frame=new System.Drawing.RectangleF(35f,130f,250f,40f); var button =UIButton.FromType (UIButtonType.RoundedRect); var frame=new System.Drawing.RectangleF(35f,30f,250f,40f); button.Frame=frame; button.SetTitle ("Button",UIControlState.Normal); button.TouchUpInside+= button_Click; this.View.AddSubview(button); this.View.AddSubview(label1); //any additional setup after loading the view, typically from a nib. } private void button_Click( object sender, EventArgs e) { label1.Text= "clicked"; }
分析代码:button.TouchUpInside+= button_Click; 事件关联。
运行结果
源代码:
下载后把gif 改成zip