iOS UITextField的基本用法

UITextField *textField = [[UITextField alloc] init];//初始化

textField.userInteractionEnabled = YES;//是否可用

textField.text = @"UITextField"; //文字

textField.delegate = self; //代理

textField.frame = CGRectMake(100, 100, 100, 40); //大小和位置

textField.textColor = [UIColor redColor];//  字体颜色

textField.placeholder = @"UITextField";//提示字符

[textField setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型UITextBorderStyleRoundedRect枚举类型

textField.secureTextEntry = YES; //密码框

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

UIImageView *imgv=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];

textField.rightView=imgv;

textField.rightViewMode = UITextFieldViewModeAlways; //右侧加图片

textField.font = [UIFont systemFontOfSize:14.0f];//文字的大小

textField.font = [UIFont boldSystemFontOfSize:14.0f];//文字加粗

textField.autocapitalizationType = UITextAutocapitalizationTypeNone;  //首字母是否自动大写

textField.clearsOnBeginEditing = YES;    //再次编辑就清空

textField.adjustsFontSizeToFitWidth = YES;  //设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动

textField.minimumFontSize = 20;   //设置自动缩小显示的最小字体大小

textField.keyboardType = UIKeyboardTypeNumberPad;   //设置键盘的样式

textField.backgroundColor = [UIColor grayColor];//背景颜色

//placeholder 颜色

//第一种

UIColor *color = [UIColor whiteColor];

textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用户名" attributes:@{NSForegroundColorAttributeName: color}];

//第二种

[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];//_placeholderLabel.textColor这个不可以修改

textField.returnKeyType =UIReturnKeyDone;   //return键变成什么键

//文字上下居中

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

//文字左右居中

textField.textAlignment = NSTextAlignmentCenter;

textField.keyboardAppearance=UIKeyboardAppearanceDefault;  //键盘外观

//UITextField左边的距离

CGRect frame = [textField frame];

frame.size.width = 15;

UIView *leftview = [[UIView alloc] initWithFrame:frame];

textField.leftViewMode = UITextFieldViewModeAlways;  //左边距为15pix

textField.leftView = leftview;

[textField becomeFirstResponder];//成为第一响应者

[self.view addSubview:textField];

时间: 2024-12-17 13:56:45

iOS UITextField的基本用法的相关文章

iOS UITextField控件总结

iOS UITextField控件总结 先声明下面总结不是自己写的. //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)]; //设置边框样式,只有设置了才会显示边框样式 text.borderStyle = UITextBorderStyleRoundedRect; typedef enum { UITextBorderStyleNone

IOS中NSSData常见用法

一.NSdata的概念 1.使用文件时需要频繁地将数据读入一个临时存储区,它通常称为缓冲区 2.NSdata类提供了一种简单的方式,它用来设置缓冲区,将文件的内容读入缓冲区,或者将缓冲区内容写到一个文件. 3.对于32位应用程序,NSdata缓存最多2GB 4.我们有两种定义 NSData(不可变缓冲区),NSMutableData(可变缓冲区) NSData *fileData; NSFileManager *fileManager = [[NSFileManager alloc]init];

IOS中NSNumber常见用法

一.NSnumber常见用法 NSNumber + (NSNumber *)numberWithInt:(int)value; + (NSNumber *)numberWithDouble:(double)value; - (int)intValue; - (double)doubleValue; -(float)floatValue; 二.使用 NSNumber * intNumber=[NSNumber numberWithInt:100]: NSNumber *floatNumber=[N

IOS中NSUserDefaults的用法(轻量级本地数据存储)

iOS数据保存 IOS中NSUserDefaults的用法(轻量级本地数据存储) IOS中NSUserDefaults的用法(轻量级本地数据存储),布布扣,bubuko.com

ios中NSUserDefaults的用法

ios中NSUserDefaults的用法 NSUserDefaults类提供了一个与默认系统进行交互的编程接口.NSUserDefaults对象是用来保存,恢复应用程序相关的偏好设置,配置数据等等.默认系统允许应用程序自定义它的行为去迎合用户的喜好.你可以在程序运行的时候从用户默认的数据库中读取程序的设置.同时NSUserDefaults的缓存避免了在每次读取数据时候都打开用户默认数据库的操作.可以通过调用synchronize方法来使内存中的缓存与用户默认系统进行同步. NSUserDefa

IOS中TableView的用法

IOS中TableView的用法 一.UITableView 1.数据展示的条件 1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITableView的dataSource数据源对象 2> 要想当UITableView的dataSource对象,必须遵守UITableViewDataSource协议,实现相应的数据源方法 3> 当UITableView想要展示数据的时候,就会给数据源发送消息(调用数据源

iOS多线程技术—NSOperation用法

iOS多线程技术—NSOperation用法 一.NSOperation简介 1.简单说明 NSOperation的作?:配合使用NSOperation和NSOperationQueue也能实现多线程编程 NSOperation和NSOperationQueue实现多线程的具体步骤: (1)先将需要执行的操作封装到一个NSOperation对象中 (2)然后将NSOperation对象添加到NSOperationQueue中 (3)系统会?动将NSOperationQueue中的NSOperat

iOS UITextField设置placeholder颜色

设置UITextField的placeholder颜色 UIColor *color = [UIColor blackColor]; textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"密码" attributes:@{NSForegroundColorAttributeName: color}]; iOS UITextField设置placeholder颜色

【iOS开发-16】UITextField协议的用法,键盘的隐藏,以及视图随着键盘的出现隐藏而上下调整位置

(1)有很多对于文本框的编辑和结束编辑的设置需要用到文本框协议,即UITextFieldDelegate:先在AppDelegate.h中加入<UITextFieldDelegate>协议,然后就可以在ViewController.m中使用.比如我们本例中对t1这个文本框对象设置了代理,代理self,即本视图控制器类,所以在本类中使用的方法都会影响t1,即可以设置t1.(最后几句为猜测,后续继续学习看是否如此). (2)当然真正的几个函数其实没甚么意思,无非就是是否允许编辑和结束编辑,如果真的