我有一个UITextView,里面有一些文字.问题是文本滚动到UITextView框的边界之外.(UITextView是不可编辑的.)
这是代码以及我试图解决此问题的方法:
- (void)viewDidLoad {
textBG.contentInset = UIEdgeInsetsZero;
// textBG.layer.masksToBounds = NO;
textBG.layer.cornerRadius = 10.0;
textBG.layer.borderWidth = 0.0;
[textBG setClipsToBounds:YES];
[super viewDidLoad];
}
- (void)textViewDidBeginEditing:(UITextView*)textView
{
textBG.contentInset = UIEdgeInsetsZero;
[textBG setClipsToBounds:YES];
}
- (void) shouldChangeTextInRange:(UITextView*)textView {
textBG.contentInset = UIEdgeInsetsZero;
[textBG setClipsToBounds:YES];
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
Mac OS X上的NSTextContainer有一个方法replaceLayoutManager:用NSLayoutManager的子类替换NSTextView的NSLayoutManager。
不幸的是iOS没有这样的功能。我尝试了这些代码行的组合,但它不断崩溃。
THLayoutManager *layoutManager = [[THLayoutManager alloc] init];
[layoutManager addTextContainer:[self textContainer]];
// [[self textStorage] removeLayoutManager:[self layoutManager]];
//[[self textStorage] addLayoutManager:layoutManager];
[[self textContainer] setLayoutManager:layoutManager];
Run Code Online (Sandbox Code Playgroud)
替换 UITextview 的 NSLayoutManager 的正确步骤是什么?