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