ios UITextField 文本输入框的用法

昨天的视图的动画是不是很有趣,那么今天我们来学习下文本输入框,这个在开放中经常用到,我们注册输入密码什么的都要用到。等学会了这个,我们就可以尝试做一个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];

    

}







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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值