Latest 0.0.1
Homepage https://github.com/visoon/VSInputView
License MIT
Platforms ios 7.0
Authors

Limit of input count in UITextField and UITextView!

Preview gif

image

Installation

pod ‘VSInputView’

Usage

UITextField

    self.VSTextField.maxLength = 20;
    //show a accessory view to show the limit of inputing text.
    self.VSTextField.showLimitLengthAccessoryView = YES;
    self.VSTextField.placeholder = @"This is textField!";

UITextView

    self.VSTextView.maxLength = 30;
    self.VSTextView.placeHolder = @"This is textView!";
    self.VSTextView.showLimitLengthAccessoryView = YES;

Core codes

- (void)vs_limitText {
    if (self.maxLength == NSIntegerMax) {
        return;
    }
    NSInteger currentInputLocation = [self vs_getCurrentInputLocation];
    NSInteger inputLength = currentInputLocation - self.preInputLocation;

    if (self.text.length > self.maxLength) {
        NSMutableString *selfText = [self.text mutableCopy];
        NSInteger needDeleteLength = self.text.length - self.maxLength;
        //calculate the range of need to be delete in whole text
        NSRange needDeleteRange = NSMakeRange(self.preInputLocation + (inputLength - needDeleteLength), needDeleteLength);
        [selfText deleteCharactersInRange:needDeleteRange];
        self.text = selfText;
    }
    self.preInputLocation = [self vs_getCurrentInputLocation];
}

Latest podspec

{
    "name": "VSInputView",
    "version": "0.0.1",
    "summary": "Limit of input count in UITextField and UITextView!",
    "description": "Limit of input count in UITextField and UITextView!!",
    "homepage": "https://github.com/visoon/VSInputView",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "vison": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/visoon/VSInputView.git",
        "tag": "0.0.1"
    },
    "source_files": [
        "VSInputView",
        "VSInputViewDemo/VSInputView/*"
    ],
    "resources": "VSInputViewDemo/VSInputView/VSInputView.bundle"
}

Pin It on Pinterest

Share This