Giter VIP home page Giter VIP logo

chltextviewlimitnum's Introduction

CHLTextViewLImitNum

限制UITextView的输入字数(支持中文和英文)以及提醒内容

下面的截图限制字数在5,中英文都算一个字

##使用指南 添加为子View

-(UITextView *)inputTextView{
    if (!_inputTextView) {
        _inputTextView = [[PlaceholderTextView alloc]initWithFrame:CGRectMake(40, 100, 300, 100)];
        _inputTextView.layer.borderColor = GET_COLOR(@"8bb9ec").CGColor;
        _inputTextView.layer.borderWidth = 1;
        _inputTextView.layer.cornerRadius = 4;
        _inputTextView.backgroundColor = COLOR_ALPHA(@"8bb9ec", 0.2);
        _inputTextView.textColor = [UIColor blackColor];
        _inputTextView.font = [UIFont systemFontOfSize:15];
        _inputTextView.delegate = self;
        _inputTextView.placeholder = @"战队简介文字输入不超过5个字";
        _inputTextView.placeholderColor = GET_COLOR(@"a1bee1");
        _inputTextView.maxLength = 5;
    }
    return _inputTextView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self.view addSubview:self.inputTextView];
}

判断最大长度需要实现如下代码

#pragma mark - textViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
 replacementText:(NSString *)text
{
    return [self.inputTextView textView:textView shouldChangeTextInRange:range replacementText:text];
    
}

chltextviewlimitnum's People

Contributors

logan-c00 avatar hh404 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.