0

1)我想在 TextView 中启用 ScrollView。当 TextView 高度增加时。

2)当我在按 Enter 后输入整行时,我正在输入的内容正在显示。但是当我在按 Enter 后仅输入 2 或 3 个字母时,我正在输入的内容没有显示。按 Enter 后显示

 -(void)viewDidLoad
{
  UITextView *txtView=[[UITextView alloc]init];
  txtView.frame = CGRectMake(60, 100, 350, 154);
  txtView.backgroundColor=[UIColor whiteColor];
  txtView.font=[UIFont fontWithName:Nil size:30];/*Font size*/
  txtView.delegate=self;
  txtView.scrollEnabled=YES;
  [self.view addSubview:txtView];
 }
 -(void)textViewDidChange:(UITextView *)textView
 { 
 if(textView.contentSize.height>textView.frame.size.height)
 {
 CGRect frame = txtView.frame;
 frame.size.height = textView.contentSize.height+90;
 textView.frame = frame;
 textView.scrollEnabled=YES;
 }
 textView.scrollEnabled=YES;
 }
4

1 回答 1

0
if(textView.contentSize.height > textView.frame.size.height)
{
    CGRect frame = textView.frame;
    frame.size.height = textView.contentSize.height + 90;
    textView.frame = frame;
    textView.scrollEnabled = YES;

    [textView setContentSize:CGSizeMake(0, textView.frame.size.height + 1)];
}
于 2013-10-05T13:07:39.950 回答