4

I have been trying to use the attributedText property of UITextView to add adjustable line height to my custom UITextView. My code works fine in the simulator, but I am unable to make it work on an iPhone5. If I remove the font line the line height works but it the text reverts to a default smaller font. If I add the font, the font works but the paragraph styling is ignored. I have tried the code on a vanilla UITextView in a fresh app with the same behavior, which makes me think this is an iOS6 bug. Has anyone had any better luck?

I have also tried various UITextView replacements to add line height functionality, but nothing has worked out so far.

My code looks like this:

...
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.minimumLineHeight = lineHeight;
paragraphStyle.maximumLineHeight = lineHeight;

NSString *text = self.text;
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];

[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, text.length)];
[attributedString addAttribute:NSFontAttributeName value:self.font range:NSMakeRange(0, text.length)];

self.attributedText = attributedString;

Thanks for any confirmation or suggestions anyone has!

Jon C
  • 41
  • 1
  • 2
  • Did you have any luck? I am also struggling with an NSAttributedString/UITextView Issue: http://stackoverflow.com/questions/15169064/how-to-consistently-draw-nsattributedstring-in-uitextview-in-uitableviewcell – Piotr Tomasik Mar 02 '13 at 00:32
  • Any updates on this answer? – Cody Winton Sep 30 '13 at 20:26

1 Answers1

3

I think this is indeed a bug. I've been struggling with it for the past few days and couldn't find any reasonable explanation.

Also, if you use IB to set up your UITextView, a few of those attributes won't be set as it should.

Anyway, I just filed a bug on that. http://openradar.appspot.com/radar?id=2278401

Matt

Abras
  • 361
  • 1
  • 4
  • 14
  • Did you have any luck? I am also struggling with an NSAttributedString/UITextView Issue: http://stackoverflow.com/questions/15169064/how-to-consistently-draw-nsattributedstring-in-uitextview-in-uitableviewcell – Piotr Tomasik Mar 02 '13 at 00:32