RAC Textfield字符数限制,最后一个字符使用中文拼音无法输入时的问题

    @weakify(self);

    [self.nameField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {

        @strongify(self);

        UITextRange*range = [self.nameFieldmarkedTextRange];

        //获取高亮部分

        UITextPosition*position = [self.nameFieldpositionFromPosition:range.startoffset:0];

        if(!position) {

            if(x.length>15) {

                self.nameField.text= [xsubstringToIndex:15];

            }

            NSMutableAttributedString *length = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%lu",(unsigned long)self.nameField.text.length]];

            length.color = self.nameField.text.length>=15?[UIColor colorWithHexString:@"#F56D6B"]:[UIColor blackColor];

            NSMutableAttributedString *total = [[NSMutableAttributedString alloc]initWithString:@"/15"];

            total.color= [UIColorcolorWithHexString:@"#000000"alpha:0.3];

            [lengthappendAttributedString:total];

            self.nameLenth.attributedText= length;

        }

    }];

你可能感兴趣的:(RAC Textfield字符数限制,最后一个字符使用中文拼音无法输入时的问题)