我想用我设置的文本量以编程方式更改 UITextView,我有一个问题,如果我用界面生成器添加 UITextView 并且我这样做:
CGRect frame = textViewA1.frame;
frame.size.height = textViewA1.contentSize.height;
textViewA1.frame = frame;
一切正常,但如果我以编程方式创建 UITextView,高度不会改变,我这样做:
UITextView *textViewA1 = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 320, 50)];
[textViewA1 setFont:[UIFont fontWithName:@"Enriqueta" size:15]];
[textViewA1 setScrollEnabled:NO];
[textViewA1 setUserInteractionEnabled:NO];
[textViewA1 setBackgroundColor:[UIColor clearColor]];
[textViewA1 setText:@"A lot of text"];
CGRect frame = textViewA1.frame;
frame.size.height = textViewA1.contentSize.height;
textViewA1.frame = frame;
这样uitextview的高度大小不会改变,我该怎么办?