Highly adaptive UITextView for iOS Dev (59)

Source: Internet
Author: User

Highly adaptive UITextView for iOS Dev (59)

 

The following _ inputTextView is a UITextView instance. First, set its delegate, and then add UITextViewDelegate to the interface declaration of your header file.

_inputTextView.delegate = self;

Implement the following methods in implementation:

-(Void) textViewDidChange :( UITextView *) textView {// obtain the original 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 above YOUR_TEXTVIEW_WIDTH is the width of your UITextView.
  • Note that NSLineBreakByWordWrapping is selected for lineBreakMode. in earlier versions, UILineBreakModeWordWrap is used.
  • size.height + 2020 is the padding that I flow out.
  • These articles are from blog.csdn.net/prevention.

    -

    Reprinted please indicate from: http://blog.csdn.net/prevention

Related Article

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.