0

As far as I know, laying out paragraphs can be done with:

a) UITextView

b) UILabel

However, I am unable to get either of these to work in IOS7 (having previously used them in ios6.x). There must be a definitive and clear way to just lay out a paragraph, its such a seemingly simple task.To be specific, this is just a paragraph of text that is:

  • non-editable
  • variable length
  • Works consistently whether using storyboards or code only

So please, what is the way to do this?

Community
  • 1
  • 1
Andrew Plummer
  • 1,150
  • 1
  • 12
  • 21

2 Answers2

0

UITextView works fine on iOS 7. If you don't use Auto Layout, then calling sizeToFit on UITextView object should be enough. If you do use Auto Layout, then make a height constraint on UITextView object and set its constant in code in the following way:

CGSize sizeThatFits = [self.textView sizeThatFits:CGSizeMake(yourAvailableWidth, MAXFLOAT)];
self.textViewHeightConstraint.constant = ceilf(sizeThatFits.height);

I've seen some problems with UILabel recently, e.g. Lines missing from tall UILabel when embedding NSTextAttachment

Community
  • 1
  • 1
Arek Holko
  • 8,966
  • 4
  • 28
  • 46
0

With the UILabel, I was able to to get this working by:

  • setting the lines to 0
  • setting my line break mode to word wrap
  • ensuring that the height constraint is set to a "greater than or equal to"
Andrew
  • 95
  • 1
  • 6