• iOS_UITextField 基本操作


    基本操作

    UITextField *userNameTextField = [[UITextField alloc] init];
        userNameTextField.frame = CGRectMake(30, 100, 220, 50);
        [self.window addSubview:userNameTextField];
        [userNameTextField release];
    
        // 设置样式
        userNameTextField.borderStyle = UITextBorderStyleRoundedRect;
        userNameTextField.placeholder = @"Enter your name";
        userNameTextField.text = @"OUTLAN";
    
        userNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; // 设置右边删除button出现时间
    
        UILabel *leftLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
        leftLable.text = @"N";
        // 设置左右视图的显示时间
        userNameTextField.leftView = leftLable;
        userNameTextField.leftViewMode = UITextFieldViewModeAlways;
        [leftLable release];
    
    
        userNameTextField.enabled = YES; // 设置是否同意输入
        userNameTextField.clearsOnBeginEditing = NO; // 输入时清空
        userNameTextField.secureTextEntry = NO; // 呈现圆点,一般用于输入password
    
    
        userNameTextField.keyboardAppearance = UIKeyboardAppearanceDark; // 控制键盘颜色为黑
        userNameTextField.keyboardType = UIKeyboardTypeEmailAddress; // 设置键盘样式
        userNameTextField.returnKeyType = UIReturnKeySearch; // 设置return按键的样式
    
    
        UIView *keyBoard = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 300)];
    
        keyBoard.backgroundColor = [UIColor greenColor];
    //    userNameTextField.inputView = keyBoard; // 替换键盘
        [keyBoard release];
    
        UIView *inputAccessView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 20)];
        inputAccessView.backgroundColor = [UIColor yellowColor];
        userNameTextField.inputAccessoryView = inputAccessView; // 辅助条
        [inputAccessView release];
    

    收回键盘

    设置代理对象。通常为self

    // 设置代理
        textFiled.delegate = self;

    当前类遵守协议

    @interface AppDelegate : UIResponder <UIApplicationDelegate, UITextFieldDelegate>

    实现协议方法

      - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        NSLog(@"点击了Return");
        [textField resignFirstResponder]; // 放弃第一响应者 收回键盘
        return YES;
    }
    
    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        NSLog(@"begining");
        return YES;
    }
    
    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
    {
        NSLog(@"ending");
        return YES;
    } 
  • 相关阅读:
    OGG常用命令
    postgres psql常用命令学习笔记
    oracle DG搭建方式两种总结
    配置rhel系统kdump安装RHEL的debuginfo软件包
    oracle开机自启,监听自启,任意秒crontab
    cx_Oracle.DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded 解决方法
    rhel | centos7上配置python3环境和pip
    shared_pool知识点整理
    记一次性能测试实践3-单接口压测
    我是如何做性能测试-文档收集并深入学习
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7358220.html
Copyright © 2020-2023  润新知