博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UITextField的详细使用
阅读量:6854 次
发布时间:2019-06-26

本文共 2558 字,大约阅读时间需要 8 分钟。

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

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

UILabel* label1 = [[UILabelallocinitWithFrame:CGRectMake(15657030)];

    label1.backgroundColor = [UIColorclearColor];

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

    label1.text = @"用户名";

    label1.textColor = [UIColorwhiteColor];

    [view1 addSubview:label1];

    [label1 release];

   UITextField * accountField = [[UITextField allocinitWithFrame:CGRectMake(85.0f60.0f190.0f40.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 = [[UILabelallocinitWithFrame:CGRectMake(151207030)];

    label2.backgroundColor = [UIColorclearColor];

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

    label2.text = @"密码";

    label2.textColor = [UIColorwhiteColor];

    [view1 addSubview:label2];

    [label2 release];

  UITextField*  passwdField = [[UITextField allocinitWithFrame:CGRectMake(85.0f115.0f190.0f40.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;

 

转载地址:http://tsyyl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
Linux集群服务知识点总结及通过案例介绍如何实现高性能web服务
查看>>
linux 运维从初级到高级的修炼
查看>>
关于Hadoop系列文章
查看>>
JAVA学习日志(7-3-抽象类)
查看>>
Linux date命令的用法(转)
查看>>
Linux shell 之 提取文件名和目录名的一些方法
查看>>
test.
查看>>
树莓派3B连接WIFI
查看>>
springMVC启动过程源码解析(一)
查看>>
linux中生成考核用的FAT32文件系统结构样例(一)
查看>>
Docker 常用命令
查看>>
eclipse快捷键
查看>>
纯虚函数和虚函数的区别
查看>>
配置adb环境变量
查看>>
Jenkins安装
查看>>
命名空间 (一)
查看>>
Django报错
查看>>
性能测试培训:分析内训泄露的案例
查看>>
javax.persistence.TransactionRequiredException: Executing an update/delete query异常
查看>>