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;//是否可以拖动 www.2cto.com

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;

ios之UITextfield (2)的更多相关文章

  1. iOS 8 swift 键盘不出来 ios 8 uitextfield keyboard not appearing

    ios 8 uitextfield keyboard not appearing //发现在iphone 6 and iPhone plus 上面键盘不出来.后来查了下原来要在模拟器里设置下 var ...

  2. iOS学习-UITextField设置placeholder的颜色

    UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(, , , )]; text.borderStyle = UITex ...

  3. IOS开发-UITextField代理常用的方法总结

    1.//当用户全部清空的时候的时候 会调用 -(BOOL)textFieldShouldClear:(UITextField *)textField: 2.//可以得到用户输入的字符 -(BOOL)t ...

  4. iOS 限制UITextField输入字符

    开篇 之前做过一个即时通信的项目,需要限制输入框文本的字符个数,当时从网络上搜寻了几个方法,解决了需求,但是网络上的解决办法不是很全面:今天又遇到一个限制搜索框UISearchBar输入字符个数的问题 ...

  5. iOS 改变UITextField中光标颜色

    第一种: [[UITextField appearance] setTintColor:[UIColor blackColor]]; 这个方法会影响整个app的所有UITextFiled... 第二种 ...

  6. IOS的UITextField,UIButton,UIWebView它描述的一些属性和IOS提示图像资源

    有时UI要开发的资源与实际frame不符.这一次,我们要绘制图片 UIImage* image = [[UIImage imageNamed:@"text_field_bg.png" ...

  7. iOS基础 - UITextField

    一.UITextField 1.常见属性 @property(nonatomic,retain) UIView *leftView; // 设置文本框左边显示什么控件,可以让文本框的内容往右边挪动 @ ...

  8. iOS中UITextField 使用全面解析

    //初始化textfield并设置位置及大小   UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 13 ...

  9. iOS中UITextField 使用全面解析 分类: ios技术 2015-04-10 14:37 153人阅读 评论(0) 收藏

    //初始化textfield并设置位置及大小   UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 13 ...

  10. iOS 之 UITextField

    UITextField 相关细节处理: 1.  设置leftView , rightView let leftView = UIView() // 设置leftView/rightView之后,勿忘设 ...

随机推荐

  1. python mixin到底是什么 django

    1.什么是Mixin 在面向对象编程中,Mixin是一种类,这种类包含了其他类要使用的方法,但不必充当其他类的父类.其他类是如何获取Mixin中的方法因语言的不同而不同.所以有时候Mixin被描述为' ...

  2. 浅谈Thrift内部实现原理

    http://dongxicheng.org/tag/thrift/ http://dongxicheng.org/search-engine/thrift-internals/ Thrift由两部分 ...

  3. C++笔试题库之编程、问答题 200~300道

    201下面的代码有什么问题?并请给出正确的写法. void DoSomeThing(char* p) { char str[16]; int n; assert(NULL != p); sscanf( ...

  4. P5166 xtq的口令

    传送门 这题要是搞懂在干什么其实不难(虽然某个花了几个小时才搞明白的家伙似乎没资格这么说--) 假设所有人都没有听到老师的命令,我们从左到右考虑,对于当前的人,如果它没有观察者,那么肯定要让它听到老师 ...

  5. Hdu 5439 Aggregated Counting (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online 找规律)

    题目链接: Hdu 5439 Aggregated Counting 题目描述: 刚开始给一个1,序列a是由a[i]个i组成,最后1就变成了1,2,2,3,3,4,4,4,5,5,5.......,最 ...

  6. Codeforces Round #544 (Div. 3) C. Balanced Team

    链接:https://codeforces.com/contest/1133/problem/C 题意: 给n个数, 在这n个数中选最多n个数,来组成一个队伍. 保证这n个数的最大最小差值不大于5. ...

  7. 中国剩余定理 POJ 1006 Biorhythms

    题目传送门 题意:POJ有中文题面 分析:其实就是求一次同余方程组:(n+d)=p(%23), (n+d)=e(%28), (n+d)=i(%33),套用中国剩余定理模板 代码: /********* ...

  8. npm install error: MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”

    When I tried to run angular 4 material2 demo on my windows server 2012, got a error message: node-pr ...

  9. JAVA常用知识总结(三)——JAVA虚拟机

    先附一张JAVA虚拟机内存结构图: 其中JAVA虚拟机的线程问题<为什么JAVA虚拟机分为线程共享和非线程共享?>一文中已经有详细介绍,本文从面试中常问的一些JAVA虚拟机问题出发,主要从 ...

  10. Spring------自动化装配Bean(二)

    上一篇是基于 @ComponentScan自动装配Bean的实现,这一篇将通过java手动装配bean来实现. 手动装配相对于自动装配的优点: 可以自行定义Bean的各个属性. 添加额外的方法调度. ...