我的开发笔记---UITextField的详细使

UItextField通常用于外部数据输入,以实现人机交互。下面以一个简单的登陆界面来讲解UItextField的详细使用。

//用来显示“用户名”的label

UILabel* label1 = [[UILabelalloc] initWithFrame:CGRectMake(15, 65, 70, 30)];

    label1.backgroundColor = [UIColorclearColor];

    label1.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];

    label1.text = @"用户名";

    label1.textColor = [UIColorwhiteColor];

    [view1 addSubview:label1];

    [label1 release];

   UITextField * accountField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 60.0f, 190.0f, 40.0f)];

[accountField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型

accountField.placeholder = @"用户名"; //默认显示的字

accountField.secureTextEntry = NO; //是否以密码形式显示

accountField.autocorrectionType = UITextAutocorrectionTypeNo;//设置是否启动自动提醒更正功能

accountField.autocapitalizationType = UITextAutocapitalizationTypeNone;

accountField.returnKeyType = UIReturnKeyDone;  //键盘返回类型

accountField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X

accountField.delegate = self;

accountField.keyboardType = UIKeyboardTypeDefault;//键盘显示类型

accountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //设置居中输入

accountField.scrollEnabled = YES;//是否可以拖动

accountField.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自适应高度

 

    //用来显示“密码”的label

    UILabel* label2 = [[UILabelalloc] initWithFrame:CGRectMake(15, 120, 70, 30)];

    label2.backgroundColor = [UIColorclearColor];

    label2.font = [UIFontfontWithName:@"Helvetica-Bold"size:18];

    label2.text = @"密码";

    label2.textColor = [UIColorwhiteColor];

    [view1 addSubview:label2];

    [label2 release];

  UITextField*  passwdField = [[UITextField alloc] initWithFrame:CGRectMake(85.0f, 115.0f, 190.0f, 40.0f)];

[passwdFieldsetBorderStyle:UITextBorderStyleRoundedRect]; //外框类型

//passwdField.placeholder = @"密码"; //默认显示的字

passwdField.secureTextEntry = YES; //密码类型

 

passwdField.autocorrectionType = UITextAutocorrectionTypeNo;   

passwdField.autocapitalizationType = UITextAutocapitalizationTypeNone;

passwdField.returnKeyType = UIReturnKeyDone;

passwdField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X

passwdField.delegate = self;

 // passwdField.keyboardAppearance = UIKeyboardAppearanceDefault;

passwdField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

passwdField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

 

委托方法

-(void)textFieldDidBeginEditing:(UITextField *)textField;  

//当开始点击textField会调用的方法    

 

 

-(void)textFieldDidEndEditing:(UITextField *)textField; 

//当textField编辑结束时调用的方法

 

//按下Done按钮的调用方法,我们让键盘消失   

-(BOOL)textFieldShouldReturn:(UITextField *)textField{  

 

 [textField resignFirstResponder];  

 return YES;

 

转载于:https://www.cnblogs.com/aipingguodeli/archive/2012/04/25/2470001.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值