Skip to content

自定义UITextView 解决换行文字被截断的效果,仿很多评论框效果

License

Notifications You must be signed in to change notification settings

lzc-ios/CXTextView

 
 

Repository files navigation

CXTextView

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

效果

使用说明

- (CXTextView *)textView{
    if (!_textView) {
        _textView = [[CXTextView alloc] initWithFrame:CGRectMake(0, 0, self.width, 100)];
        _textView.initiLine = 2;
        _textView.maxLine = 4;
        _textView.v_margin = 10;
        _textView.h_margin = 15;
        _textView.maxLength = 500;
        _textView.placeholder = @"说点什么吧";
        _textView.backgroundColor = [UIColor whiteColor];
        _textView.textView.tintColor = CXRGB(234, 111, 91);
        _customTextViewHeight = ceil(_textView.font.lineHeight * _textView.initiLine) + 2*_textView.v_margin;
        //高度改变
        __weak __typeof(self)weakSelf = self;
        _textView.textHeightChangeBlock = ^(CGFloat height) {
            __strong __typeof(weakSelf)sSelf = weakSelf;
            if (sSelf->_customTextViewHeight != height) {
                sSelf->_customTextViewHeight = height;
                [sSelf setNeedsLayout];
                [sSelf layoutIfNeeded];
            }
        };
        //文字改变
        _textView.textDidChangeHandlerBlock = ^(UITextView *textView) {
            __strong __typeof(weakSelf)sSelf = weakSelf;
            if ([[textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0) {
                sSelf.toolBarView.canClick = NO;
            } else {
                sSelf.toolBarView.canClick = YES;
            }
        };
        //最大字数回调
        _textView.textLengthDidMaxHandlerBlock = ^(UITextView * _Nonnull textView) {
            NSLog(@"👱弹出自己业务的提示👱");
        };
    }
    return _textView;
}

Installation

CXTextView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'CXTextView'

Author

616704162@qq.com 小作坊开发者

License

CXTextView is available under the MIT license. See the LICENSE file for more info.

About

自定义UITextView 解决换行文字被截断的效果,仿很多评论框效果

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 96.2%
  • Ruby 3.8%