在iOS Mail应用中,当您点击回复时,会看到一个像这样的文本视图。当您尝试在进行内联回复时编辑上一个回复时,垂直蓝线会继续增长或缩小(视情况而定)。顶部(您的主要回复)看起来很正常。关于如何拉开这种文本视图的真正顶级的想法?
答案 0 :(得分:7)
textViewHolder = [[UIView alloc]initWithFrame:CGRectMake(20, 100, 280, 20)];
simpleLine = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 2, 20)];
simpleLine.backgroundColor = [UIColor blueColor];
[textViewHolder addSubview:simpleLine];
myTextView = [[UITextView alloc]initWithFrame:CGRectMake(20, 0, 240, 24)];
myTextView.delegate = self;
[textViewHolder addSubview:myTextView];
[self.view addSubview:textViewHolder];
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
{
int numLines = myTextView.contentSize.height / myTextView.font.lineHeight;
if([text isEqualToString:@"\n"])
numLines++;
if(numLines>1)
{
CGRect frame = textViewHolder.frame;
frame.size.height = 20*(numLines-1);
textViewHolder.frame =frame;
CGRect frame2 = simpleLine.frame;
frame2.size.height = 20*(numLines-1);
simpleLine.frame =frame2;
CGRect frame3 = myTextView.frame;
frame3.size.height = 24*(numLines-1);
myTextView.frame =frame3;
}
return YES;
}
(numLines-1)
是因为我总是得到一条我需要的线。我确信它可以通过一些调试来解决。
[text isEqualToString:@"\n"]
部分是因为如果用户按下完成并按下一行,您还希望增加行号。