IOS Dev (59) Highly adaptive Uitextview
Arri Address: Http://blog.csdn.net/prevention
-
The following _inputtextview is a Uitextview instance. The first thing to do is to set its delegate, and then add uitextviewdelegate to the interface declaration of your header file.
_inputTextView.delegate = self;
The following methods are implemented in implementation:
- (void)textViewDidChange:(UITextView *)textView{ // 获取原来的 frame CGRect tmpRect = _inputTextView.frame; CGSize size = [_inputTextView.text sizeWithFont:[UIFont systemFontOfSize:_inputTextFontSize] constrainedToSize:CGSizeMake(YOUR_TEXTVIEW_WIDTH, 2000) lineBreakMode:NSLineBreakByWordWrapping]; tmpRect.size.height = size.height + 20; // 20 points for padding tmpRect.origin.y = keyboardPositionY - tmpRect.size.height; _inputTextView.frame = tmpRect; _inputTextView.text = _inputTextView.text;}
- Note that the your_textview_width above is the width of your uitextview.
- Note Linebreakmode selected Nslinebreakbywordwrapping, the older version is uilinebreakmodewordwrap.
size.height + 2020 of the padding I shed.
- This batch of the article from Blog.csdn.net/prevention, reprint please specify.
-
reprint Please specify from: Http://blog.csdn.net/prevention