C#iphone UIButton 的使用

想学用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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值