zoukankan      html  css  js  c++  java
  • iOS UI基础

        //找到已经创建好的UITextField
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(50, 100, RFSCREEN_W - 100 , 45)];
        textField.leftImageName = @"login_user_icon"
        //设置边框样式
        textField.borderStyle = UITextBorderStyleNone;
        //通过layer设置圆角
        //textField.layer.cornerRadius = 10;
        textField.layer.borderColor = Color_White.CGColor;
        textField.layer.borderWidth = 1;
        // 设置字体颜色
        textField.textColor = Color_White;
        // 输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
        textField.clearButtonMode = UITextFieldViewModeAlways;
        //第一响应者,一个界面可能有多个可输入的控件,哪一个正在编辑哪一个就是第一响应者
        [textField becomeFirstResponder];
        // 设置左边图标
        UIImageView *leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"login_user_icon"]];
        leftImageView.frame = CGRectMake(0, 0, 50, 50);
        leftImageView.contentMode = UIViewContentModeCenter;
        textField.leftView = leftImageView;
        //设置左视图的显示模式
        textField.leftViewMode = UITextFieldViewModeAlways;
        // 设置键盘的样式
        textField.keyboardType = UIKeyboardTypeNumberPad;
        // 设置占位文字
        textField.placeholder = @"请输入用户名";
        // 设置占位文字的颜色
        [textField setValue:Color_White forKeyPath:@"placeholderLabel.textColor"];
        
        [self.view addSubview:textField];

     限定只可以输入数字和6位长度

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        NSString *text = [textField text];
        NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
        string = [string stringByReplacingOccurrencesOfString:@" " withString:@""];
        if ([string rangeOfCharacterFromSet:[characterSet invertedSet]].location != NSNotFound) {
            return NO;
        }
        text = [text stringByReplacingCharactersInRange:range withString:string];
        text = [text stringByReplacingOccurrencesOfString:@" " withString:@""];
        
        if ([text stringByReplacingOccurrencesOfString:@" " withString:@""].length >= 7) {
            return NO;
        }
        
        [textField setText:text];
        _confirmButton.enabled = text.length > 0 ? YES : NO;
        return NO;
    }
  • 相关阅读:
    python学习笔记(十一)处理json
    python学习笔记(十)常用模块
    python学习笔记(九)内置函数
    python学习笔记(八)函数return多个值,列表推导式和交换两个变量的值
    BZOJ 3675 [Apio2014]序列分割 (斜率优化DP)
    BZOJ 3126 [USACO2013 Open]Photo (单调队列优化DP)
    POJ 1821 Fence (单调队列优化DP)
    BZOJ 3326 [SCOI2013]数数 (数位DP)
    HDU 6148 Valley Numer (数位DP)
    BZOJ 2741 L (可持久化01Trie+分块)
  • 原文地址:https://www.cnblogs.com/jys509/p/5343451.html
Copyright © 2011-2022 走看看