C#iphone UITextField 的使用

想学用C#开发iphone 的就加入 QQ群:178290571 ,让我们共同进步吧!

C# MonoTouch for iphone 开发blog  http://blog.csdn.net/ssihc0/

MonoDevelop 版本:2.8.0

MonoTouch 版本:4.2.2


UITextField 和windows 下的textbox 差不多,它为我们提供了一种文本编辑功能的控件,并且对于编辑密码或其它安全数据提供保护,以*星号显示。当用户单击UITextField时,会出现在一个键盘,

介绍一下一些属性

   Text  实际显示的文本。

   Placeholder 用来提示要输入什么样的数据。

   TextAlignment  使用UITextAlignment 枚举选择Left,Center  或Right 对齐方式。

   TextColor 指定颜色。

   SecureTextEntry 是否(用星号) 掩码隐藏显示的文本。

   KeyboardType 允许控件显示合适所需数据类型的键盘。例如纯文本,email,或数值数据。


下面是方法和属性:


新建一个工程名为TextField 打开TextFieldViewController

 添加下面代码

	private UITextField textBox1;
		private UIButton  button;
		public TextFieldViewController (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 ();
			this.View.BackgroundColor=UIColor.White;
		    textBox1= new UITextField( new System.Drawing.RectangleF(35f,130f,150f,40f) );
			textBox1.Font= UIFont.FromName("Times New Roman",27f);
			textBox1.Placeholder="Input String";
			textBox1.SecureTextEntry=false;
			button= UIButton.FromType(UIButtonType.RoundedRect);
			button.Frame=new System.Drawing.RectangleF(35f,30f,60f,40f);
			button.SetTitle("Done",UIControlState.Normal);
			button.TouchUpInside += button_click;
			this.View.Add(textBox1);
			this.View.Add(button);
			
			//any additional setup after loading the view, typically from a nib.
		}
		private void button_click(object sender,EventArgs e)
		{
			textBox1.ResignFirstResponder();
		}
		
		


代码分析:

textBox1.ResignFirstResponder();
 是隐藏键盘!


运行结果


源代码:

下载

下载后把gif 改成zip


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值