zoukankan      html  css  js  c++  java
  • IOS UI TextFiled常用总结

    首先先创建一个UITextField作为例子
    
    //1.输入框的基本使用(创建显示,回收键盘)
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 100, 300, 30)];
        //输入框默认没有边框, 添加边框
        textField.borderStyle = UITextBorderStyleRoundedRect;
        [self.view addSubview:textField];
    以下是常用属性
    
    //2.常用属性
        //<1>文本字体
        //textField.font
        //<2>文本颜色
        //textField.textColor
        //<3>设置密码输入键盘
        textField.secureTextEntry = YES;
        //<4>设置键盘类型(设置数字键盘)
        textField.keyboardType = UIKeyboardTypeNumberPad;
        //<5>设置清除模式
        textField.clearButtonMode = UITextFieldViewModeAlways;
        //<6>设置空白提示(输入提示)
        textField.placeholder = @"请输入密码";
        //<7>设置是否自动大写
        textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
        //<8>是否自动显示修正后的单词
        textField.autocorrectionType = UITextAutocorrectionTypeNo;
        //<9>设置文本对齐方式
        textField.textAlignment = NSTextAlignmentRight;
        //<10>设置背景图片(需要边框类型设置为UITextBorderStyleNone)
        textField.background = [UIImage imageNamed:@"back.png"];
        //<11>左侧提示图片
        textField.leftViewMode = UITextFieldViewModeAlways;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        imageView.image = [UIImage imageNamed:@"Icon-Small-50.png"];
        textField.leftView = imageView;
    
    关闭键盘的两种方式
    第一种:textField放弃第一响应者身份,使用这种方式要记得加入UITextFieldDelegate协议和自身delegate的设置,
    即textField.delegate = self;
    这样才能实现点击return按钮回收键盘功能
    
    -(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        //放弃作为第一响应者
        [textField resignFirstResponder];
        return YES;
    }
    第二种是点击空白处回收键盘,注意:要是使用textField放弃第一响应者身份这个方式要记得把
    textField设置为全局变量,
    因为这个方法名里没有textField这个参数
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        //[_textField resignFirstResponder];
        [self.view endEditing:YES];
    }
    与textField有关的属性就总结到这里,希望对初学者提供帮助
    

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    shell 操作钉钉机器人实现告警提醒
    谨慎 mongodb 关于数字操作可能导致类型及精度变化
    数据库如何应对保障大促活动
    SQL Server Alwayson架构下 服务器 各虚拟IP漂移监控告警的功能实现 -1(服务器视角)
    通过 Telegraf + InfluxDB + Grafana 快速搭建监控体系的详细步骤
    MySQL数据库Inception工具学习与测试 笔记
    MongoDB 中数据的替换方法实现 --类Replace()函数功能
    MongoDB 中的【加减乘除】运算
    MySQL索引设计需要考虑哪些因素?
    关于SQL Server 数据库归档的一些思考和改进
  • 原文地址:https://www.cnblogs.com/yuqingzhude/p/4836542.html
Copyright © 2011-2022 走看看