Reputation: 41
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!
Upvotes: 4
Views: 3975
Reputation: 361
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
Upvotes: 3