UITextView is so buggy on iOS6/iOS7...
line spacing
// adjust lineSpacing
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.minimumLineHeight = LINE_HEIGHT;
style.maximumLineHeight = LINE_HEIGHT;
style.lineHeightMultiple = LINE_HEIGHT;
// Bug: NSFontAttributeName not working in ios6
NSDictionary *attributes = @{
NSParagraphStyleAttributeName : style,
};
[textView setAttributedText:[[NSAttributedString alloc] initWithString:content attributes:attributes]];
font size
//Fixed: font-size not working in ios6
[textView setEditable:YES];
[textView setFont:[UIFont fontWithName:@"Helvetica" size:FONT_SIZE]];
[textView setEditable:NO];
contentSize
// in iOS6
[textView sizeToFit];
NSLog(@"height:%f", [textView contentSize].height);
in iOS6
height: 416
not working in iOS7
height: 292
[textView setFrame:CGRectMake(10, 10, 300, [self measureHeightOfUITextView:textView])];
NSLog(@"height:%f", [self measureHeightOfUITextView:textView]);
- (CGFloat)measureHeightOfUITextView:(UITextView *)textView
{
return [textView sizeThatFits:CGSizeMake(textView.frame.size.width, FLT_MAX)].height;
}
Fixed:
in iOS6
height: 416
in iOS7
height: 366
Added a screenshot for the final results.
combining all code.
I also create an category for UITextView+Additions.