zoukankan      html  css  js  c++  java
  • textFiled输入字数的控制问题之—把带输入的拼音也判断了

    一个textFiled,控制只能输入五个字,现在你已经输入了四个字,在输入第五个字的时候,输入一个拼音之后就不能输入后一个拼音,这里把拼音也当成字来判断了,这种情况下就需要_textFiled.markedTextRange这个属性,也就是当你待输入的拼音为空的时候再进行判断是不是超过五个字了。就不考虑拼音待输入的时候的状态了。

    -(void)viewWillAppear:(BOOL)animated{

        [super viewWillAppear:animated];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFiledDidChangeAction) name:UITextFieldTextDidChangeNotification object:nil];

    }

    -(void)viewWillDisappear:(BOOL)animated{

        [super viewWillDisappear:animated];

        [[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:nil];

    }

    if (_textFiled.markedTextRange == nil) 

    textFiled字数控制用通知,别用代理方法

    -(void)textFiledDidChangeAction{

        if (self.shisentifyView.inputTextfield.text.length>4&&self.shisentifyView.inputTextfield.markedTextRange==nil) {

            NSString * str = [NSString stringWithFormat:@"%@",[self.shisentifyView.inputTextfield.text substringToIndex:4]];

            [self.shisentifyView.inputTextfield setText:str];

        }

    }

  • 相关阅读:
    我的公众号:WebHub
    The Qt Resource System
    Node.js Streams:你需要知道的一切
    2019春招前端面试预测题!
    BeamNG.drive物理引擎评鉴
    EcmaScript对象克隆之谜
    死锁与囚徒困境的辩证关系
    停止学习框架
    qt5android
    opencvKmeans图像分割根据颜色
  • 原文地址:https://www.cnblogs.com/Jordandan/p/5530022.html
Copyright © 2011-2022 走看看