美文网首页
UITextField

UITextField

作者: 七维树 | 来源:发表于2018-06-08 18:38 被阅读15次

    光标颜色,高度/宽度

    //全部光标
     [[UITextField appearance] setTintColor:[UIColor blackColor]];
    //单个光标
    _textField.tintColor = [UIColor redColor];
    //宽高
    - (CGRect)caretRectForPosition:(UITextPosition *)position
    {
        CGRect originalRect = [super caretRectForPosition:position];
        
        originalRect.size.height = self.font.lineHeight + 2;
        originalRect.size.width = 5;
     
        return originalRect;
    }
    

    自动输入

    [_textField becomeFirstResponser];
    

    禁用/关闭 粘贴选择全选

    //部分关闭
    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
        {
            if (action == @selector(paste:))//禁止粘贴
                return NO;
            if (action == @selector(select:))// 禁止选择   
                return NO;   
            if (action == @selector(selectAll:))// 禁止全选   
                return NO;  
            return [super canPerformAction:action withSender:sender];
        }
    
    //全部关闭
    -(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
        UIMenuController *menuController = [UIMenuController sharedMenuController];
        if (menuController) {
            [UIMenuController sharedMenuController].menuVisible = NO;
        }
        return NO;
    }
    

    初始设置

    _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            _textField.font = fontBoldCondensed11;
            _textField.textColor = colorBlack000000;
            _textField.tintColor = colorClear;
            _textField.keyboardType = UIKeyboardTypeDecimalPad;
            _textField.autocorrectionType = UITextAutocorrectionTypeNo;//自动改成正
            _textField.spellCheckingType = UITextSpellCheckingTypeNo;//自动朗读
            _textField.autocapitalizationType = UITextAutocapitalizationTypeNone;//首字母大写
            _textField.placeholder = _L(@"MEMO_TAP_TO_INPUT");
            _textField.rightView = self.phoneIndicatorView;
            _textField.rightViewMode = UITextFieldViewModeNever;
            [_textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    

    相关文章

      网友评论

          本文标题:UITextField

          本文链接:https://www.haomeiwen.com/subject/cooasftx.html