IOS Dev (59) Highly adaptive Uitextview

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.