【发布时间】:2015-12-07 13:34:31
【问题描述】:
从几天开始,我试图创建一个UITextView,其中width 和height 是fixed。并且随着用户类型其内容大小的增加。这样线路就不会断了。
用户感觉他正在输入一行。
如果他水平滚动,那么他可以滚动UITextView 的content,而不是在UITextView 中录音。
我正在使用这段代码来实现:
- (void)viewDidAppear:(BOOL)animated
{
UITextView *txtView = [[UITextView alloc]initWithFrame:CGRectMake(10, 100, 200, 50)];
txtView.text = @"Hello";
txtView.backgroundColor = [UIColor redColor];
txtView.delegate = self;
[txtView setFont:[UIFont fontWithName:@"ArialMT" size:40]];
txtView.contentSize =txtView.frame.size;
[self.view addSubview:txtView];
}
//Delegate method
-(void)textViewDidChange:(UITextView *)tView
{
if (tView.text.length > 8) {
// Set some higher width of the text view content size.
tView.contentSize = CGSizeMake(200.0f, tView.frame.size.height);
}
}
但它似乎不起作用。当我到达末尾时,我的光标移到了下一行。
我在 Google And SO 中搜索过。
找到这些链接,但它们似乎不起作用。
【问题讨论】:
-
你尝试将 textview 添加到 scrollview 吗?
标签: ios objective-c iphone uiscrollview uitextview