After a lot of work, I found another solution if you are just developing for iOS 6. Set the top and bottom margins using contentInset :
textView = [[UITextView alloc] init]; textView.contentInset = UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0);
For left and right margins, do not add your plain text at once, but use NSAttributedString , and then correctly set the left and right margins using NSMutableParagraphStyle :
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.headIndent = 20.0; paragraphStyle.firstLineHeadIndent = 20.0; paragraphStyle.tailIndent = -20.0; NSDictionary *attrsDictionary = @{NSFontAttributeName: [UIFont fontWithName:@"TrebuchetMS" size:12.0], NSParagraphStyleAttributeName: paragraphStyle}; textView.attributedText = [[NSAttributedString alloc] initWithString:myText attributes:attrsDictionary];
This gives you a UITextView with your text (in my case from the myText variable) with a 20 pixel fill that scrolls correctly.
Eric Böhnisch-Volkmann Apr 05 '13 at 10:36
source share