CXTextView
示例
要运行示例项目,请先克隆仓库,然后从 Example 目录首先运行 pod install
。
使用说明
- (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;
}
安装
CXTextView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中:
pod 'CXTextView'
作者
[email protected] 小作坊开发者
许可证
CXTextView可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。