zoukankan      html  css  js  c++  java
  • 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;
    } 
  • 相关阅读:
    LOJ 3055 「HNOI2019」JOJO—— kmp自动机+主席树
    LOJ 2586 「APIO2018」选圆圈——KD树
    bzoj 3600 没有人的算术——二叉查找树动态标号
    bzoj 1257 余数之和 —— 数论分块
    bzoj 3998 弦论 —— 后缀自动机
    bzoj 2946 公共串 —— 后缀自动机
    bzoj 4032 [ HEOI 2015 ] 最短不公共子串 —— 后缀自动机+序列自动机
    bzoj 2555 SubString —— 后缀自动机+LCT
    洛谷 P3804 [模板] 后缀自动机
    洛谷 P4106 / bzoj 3614 [ HEOI 2014 ] 逻辑翻译 —— 思路+递归
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7358220.html
Copyright © 2011-2022 走看看