Because the original code use inheritance which is too intrusive, now I use category to reconstruct the code, and released new version 。
- For iOS8 :
use_frameworks!
target '<Your Target Name>' do
pod 'UITextView CMInputView'
end
- Drag all files under
CMInputView/CMInputView/Class
folder into your project.
Firstly, you need import the .h file.
if cocoaposd:
#import <UITextView CMInputView.h>
if manually:
#import "UITextView CMInputView.h"
Then create UITextView and use this category to configure .
UITextView * inputView = [[UITextView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 55)];
inputView.font = [UIFont systemFontOfSize:18];
inputView.cm_placeholder = @"UITextView CMInputView";
inputView.cm_placeholderColor = [UIColor redColor];
inputView.cm_maxNumberOfLines = 3;
[self.view addSubview:inputView];
If you want to make the UITextView break line automatically ,you can write like this:
UITextView * inputView = [[UITextView alloc]initWithFrame:CGRectMake(0, 100, self.view.bounds.size.width, 55)];
inputView.font = [UIFont systemFontOfSize:18];
inputView.cm_placeholder = @"UITextView CMInputView";
inputView.cm_placeholderColor = [UIColor redColor];
inputView.cm_autoLineBreak = YES;
[self.view addSubview:inputView];
Congratulations! You're done. 🎉
- The category do not support constrained layout,please use carefully !
- Once you set
cm_maxNumberOfLines
,the effect always works,even if you setYES
tocm_autoLineBreak
"UITextView CMInputView" is available under the MIT license. See the LICENSE file for more info.