ios UITextField 文本输入框的用法
2015-02-13 11:41
267 查看
昨天的视图的动画是不是很有趣,那么今天我们来学习下文本输入框,这个在开放中经常用到,我们注册输入密码什么的都要用到。等学会了这个,我们就可以尝试做一个nice的界面,这个我会放在下一个博客,希望大家好好学。
那么今天我们来创建一个新的工程:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
self.window = [[UIWindow
alloc]initWithFrame:[[UIScreen
mainScreen] bounds]];
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[self
creadTextField];
[self
createTextFileld2];
return
YES;
}
-(void)creadTextField
{
//创建一个文本输入框
UITextField *tf = [[UITextField
alloc]init];
//指定输入框的位置和大小
tf.frame =
CGRectMake(30,
50, 300,
40);
//文本输入框的背景颜色
tf.backgroundColor = [UIColor
whiteColor];
//文本输入框的风格(我这里选择圆角矩形,还有几种风格可以看文档)
tf.borderStyle =
UITextBorderStyleRoundedRect;
//文本输入框的文字颜色
tf.textColor = [UIColor
brownColor];
//字体尺寸
tf.font = [UIFont
systemFontOfSize:22];
//设置站位符
tf.placeholder =
@"请输入账户";
//设置清除按钮(就是我们输错密码时可以删除重新输入的叉号按钮)
tf.clearButtonMode =
UITextFieldViewModeWhileEditing;
//这个大家可以定制按钮,然后添加在这上面
UIView *view = [[UIView
alloc]init];
view.frame =CGRectMake(0,
0, 50,
30);
view.backgroundColor = [UIColor
redColor];
//设置文本输入框右视图
tf.rightView = view;
//设置右视图的显示模式
tf.rightViewMode =
UITextFieldViewModeWhileEditing;
//设置弹出的键盘为数字键盘
tf.keyboardType =
UIKeyboardTypeNumberPad;
//设置键盘上的返回按钮
tf.returnKeyType =
UIReturnKeyGo;
[self.window
addSubview:tf];
}
-(void)createTextFileld2
{
UITextField *tf = [[UITextField
alloc]init];
tf.frame =
CGRectMake(30,
150, 300,
40);
tf.backgroundColor = [UIColor
whiteColor];
tf.borderStyle =
UITextBorderStyleLine;
tf.textColor =[UIColor
redColor];
tf.font = [UIFont
systemFontOfSize:22];
tf.placeholder =
@"请输入密码";
//设置密文输入
tf.secureTextEntry =
YES;
//设置文本输入框是否在编辑时候清空
tf.clearsOnBeginEditing =
YES;
//设置或者取得文本输入框的内容
// tf.text = @"hsajdhashd";
//设置输入框的背景图片
tf.background = [UIImage
imageNamed:@"Baseball.png"];
[self.window
addSubview:tf];
}
那么今天我们来创建一个新的工程:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
self.window = [[UIWindow
alloc]initWithFrame:[[UIScreen
mainScreen] bounds]];
self.window.backgroundColor = [UIColor
whiteColor];
[self.window
makeKeyAndVisible];
[self
creadTextField];
[self
createTextFileld2];
return
YES;
}
-(void)creadTextField
{
//创建一个文本输入框
UITextField *tf = [[UITextField
alloc]init];
//指定输入框的位置和大小
tf.frame =
CGRectMake(30,
50, 300,
40);
//文本输入框的背景颜色
tf.backgroundColor = [UIColor
whiteColor];
//文本输入框的风格(我这里选择圆角矩形,还有几种风格可以看文档)
tf.borderStyle =
UITextBorderStyleRoundedRect;
//文本输入框的文字颜色
tf.textColor = [UIColor
brownColor];
//字体尺寸
tf.font = [UIFont
systemFontOfSize:22];
//设置站位符
tf.placeholder =
@"请输入账户";
//设置清除按钮(就是我们输错密码时可以删除重新输入的叉号按钮)
tf.clearButtonMode =
UITextFieldViewModeWhileEditing;
//这个大家可以定制按钮,然后添加在这上面
UIView *view = [[UIView
alloc]init];
view.frame =CGRectMake(0,
0, 50,
30);
view.backgroundColor = [UIColor
redColor];
//设置文本输入框右视图
tf.rightView = view;
//设置右视图的显示模式
tf.rightViewMode =
UITextFieldViewModeWhileEditing;
//设置弹出的键盘为数字键盘
tf.keyboardType =
UIKeyboardTypeNumberPad;
//设置键盘上的返回按钮
tf.returnKeyType =
UIReturnKeyGo;
[self.window
addSubview:tf];
}
-(void)createTextFileld2
{
UITextField *tf = [[UITextField
alloc]init];
tf.frame =
CGRectMake(30,
150, 300,
40);
tf.backgroundColor = [UIColor
whiteColor];
tf.borderStyle =
UITextBorderStyleLine;
tf.textColor =[UIColor
redColor];
tf.font = [UIFont
systemFontOfSize:22];
tf.placeholder =
@"请输入密码";
//设置密文输入
tf.secureTextEntry =
YES;
//设置文本输入框是否在编辑时候清空
tf.clearsOnBeginEditing =
YES;
//设置或者取得文本输入框的内容
// tf.text = @"hsajdhashd";
//设置输入框的背景图片
tf.background = [UIImage
imageNamed:@"Baseball.png"];
[self.window
addSubview:tf];
}
相关文章推荐
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- iOS开发-UITextField(输入框)用法详解
- Swift 开发: 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- UITextField AutoComplete iOS输入框内文本自动完成
- Swift - 文本输入框(UITextField)的用法
- iOS个人整理04-UITextField文本输入框
- Swift - 文本输入框(UITextField)的用法
- Swift - 文本输入框(UITextField)的用法
- UITextField 文本字段控件-IOS开发
- IOS 文本输入框奇妙的崩溃原因
- ios中实现对UItextField,UITextView等输入框的字数限制
- 给iOS开发新手送点福利,简述UITextField的属性和用法
- iOS SDk:创建一个自定义文本输入框
- IOS学习笔记36—解决键盘遮挡输入框(UITextField)问题
- iOS SDK:创建一个自定义文本输入框
- iOS SDK:创建一个自定义文本输入框