【iOS学习】----UITextField

    nameField = [[UITextField alloc] init];
    nameField.frame = CGRectMake(35, 130, 250, 35);
    nameField.delegate = self;
    //边界风格
    nameField.borderStyle = UITextBorderStyleRoundedRect;
    //文字在竖直方向的位置
    nameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    //没有输入时显示的文字,输入之后小时,作提示用
    nameField.placeholder = @"please input your email:";
    //键盘返回键类型
    nameField.returnKeyType = UIReturnKeyDone;
    //当编辑的时候有一个x,提示可以一次删除UITextField中全部内容,需要代理配合实现
    nameField.clearButtonMode = UITextFieldViewModeWhileEditing;
    //键盘类型 
    nameField.keyboardType = UIKeyboardTypeEmailAddress;
    //标记
    nameField.tag = 1001;
    //文本框中文本的颜色
    nameField.textColor = [UIColor blueColor];
    //设置文本框可以显示的最小字体,minimumFontSize,adjustsFontSizeToFitWidth必须配合使用才有效果
    nameField.minimumFontSize = 8;
    nameField.adjustsFontSizeToFitWidth = YES;
    //输入文字的字体
    nameField.font = [UIFont systemFontOfSize:20];
    //只有至少在文本框输入一个字符后键盘的返回键才有效
    nameField.enablesReturnKeyAutomatically = YES;
    //密码风格
    nameField.secureTextEntry = YES;
    //设置大写
    //None : 不设置大写
    //Words : 每个单词首字母大写,这里的单词指的是以空格分开的字符串
    //Sentances : 每个句子的第一个字母大写,这里的句子是以句号加空格分开的字符串
    //All Characters : 所以字母大写
    nameField.autocapitalizationType = UITextAutocapitalizationTypeSentences;
    [self.view addSubview:nameField];


常用代理方法:

1.开始编辑:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;

2.点击return按钮所做的动作:
- (BOOL)textFieldShouldReturn:(UITextField *)textField;

3.是否一次完全清除:
- (BOOL)textFieldShouldClear:(UITextField *)textField;

4.编辑完成:
- (void)textFieldDidEndEditing:(UITextField *)textField;

文本为空的时候,send(发送)按钮不可用:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
	NSMutableString *newValue = [[textField.text mutableCopy] autorelease];
	[newValue replaceCharactersInRange:range withString:string];//string是当前输入的字符,newValue是当前输入框中的字符
	if ([newValue length]== 0)
        {
		sendBtn.enabled =  NO;
	}
	else
        {
  		sendBtn.enabled = YES;
	}
	return YES;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值