以编程方式创建的UITextView不再使用iOS 9滚动

时间:2015-09-19 14:39:44

标签: ios objective-c uitextview ios9

以下代码以编程方式创建一个文本视图,该文本视图在文本超出设备屏幕高度时滚动。代码在iOS 7和iOS 8中没有问题。但是,文本字段不再使用相同代码的iOS 9滚动。通过几个小时的尝试找到修复,这个问题非常令人沮丧,所以我非常感谢任何帮助。提前致谢。这是代码:

- (void)createTextView

{

//1. Create the text storage that backs the editor.
NSDictionary *attrs = @{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]};
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:notesAndReference attributes:attrs];
_textStorage = [[SyntaxHighlightTextStorage alloc] init];
[_textStorage appendAttributedString:attrString];

CGRect newTextViewRect = self.view.bounds;

//2. Create the layout manager.
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];

//3. Create a text container.
CGSize containerSize = CGSizeMake(newTextViewRect.size.width, CGFLOAT_MAX);
NSTextContainer *container = [[NSTextContainer alloc] initWithSize:containerSize];
container.widthTracksTextView = YES;
[layoutManager addTextContainer:container];
[_textStorage addLayoutManager:layoutManager];

//4. Create a UITextView.
textView = [[UITextView alloc] initWithFrame:newTextViewRect textContainer:container];
textView.scrollEnabled = YES;
textView.editable = YES;
textView.delegate = self;
[self.view addSubview:textView];

}

0 个答案:

没有答案