Thursday, October 3, 2013

iOS 7 (XCode 5) Tutorial - ContentSize of Text View is not calculating correctly any more with iOS 7

iOS 7 (XCode 5) ContentSize of Text View is not calculating correctly any more with iOS 7


Before X Code 5, to get the contents height of text view we use text view's property contentSize. But its no longer work with new iOS 7. 

Option 1:

With iOS 7, we have a different property named textContainer. It gives text container of text view. 

You need to replace the following line of code (These line of code set the text view frame according to its content length.)

 CGRect frame = _textView.frame;
 frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

with 

CGRect frame = _textView.frame;
 frame.size.height = _textView.textContainer.size.height;
 _textView.frame = frame;

_textView.textContainer.size gives the same value which was given by _textView.contentSize earlier.

Option 2:

We can also replace the line of code 


 CGRect frame = _textView.frame;
 frame.size.height = _textView.contentSize.height;
_textView.frame = frame;

with 

CGRect frame = _textView.frame;
 frame.size.height = [_textView sizeThatFits:CGSizeMake(txtView.frame.size.width, MAXFLOAT)].height;
 _textView.frame = frame;

Above lines of code will work with each iOS.






6 comments:

  1. Thanks for your ideas. You can also find the details on Affity Solutions, at the Iphone Developers. The main object of the Affity Solutions is to provide quality web services and is among the few software development company in Nagpur.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Great blog article informative I liked it

    We are the best piping design course in Hyderabad, India. Sanjary academy Offers Piping Design Course and Best Piping Design Training Institute in Hyderabad. Piping Design Institute in India Piping Design Engineering.
    best Piping Design Course
    piping design course with placement
    pipe stress analysis course in hyderabad
    piping engineering course in hyderabad
    piping stress analysis course
    best Piping Design institute
    best institute of Piping Design Course in India
    Piping Design Course
    Piping Design Course in India­

    ReplyDelete

  4. Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well I really get amazed to read this. It's really good.
    I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!.






    mobile phone repair in Fredericksburg
    iphone repair in Fredericksburg
    cell phone repair in Fredericksburg
    phone repair in Fredericksburg
    tablet repair in Fredericksburg
    mobile phone repair in Fredericksburg
    mobile phone repair Fredericksburg
    iphone repair Fredericksburg
    cell phone repair Fredericksburg
    phone repair Fredericksburg

    ReplyDelete
  5. iOS 7 (XCode 5) Tutorial - ContentSize of Text View is not calculating correctly any more with iOS 7 (post looks interesting..)

    Helpful for developers, students to learn..
    Top 5 Important Tips To Know Before Hiring An iOS Developer

    hire ios app developers

    ReplyDelete
  6. As an iPhone/iOS application developer, staying ahead in the ever-evolving landscape of app development is paramount. That's why partnering with the Best apps development Company in Hyderabad can truly make a difference in your journey towards success.

    ReplyDelete