iphone - UITextView 就像 Mail.app 回复 View 中一样

标签 iphone ios6 uiwebview ios7 uitextview

在 iOS 邮件应用程序中,当您点击回复时,您会看到这样的 TextView 。当您在进行内联回复或其他操作时尝试编辑上一个回复时,垂直蓝线会不断增大或缩小(视情况而定)。顶部(您的主要回复)看起来很正常。关于如何实现这种 TextView ,您有什么真正顶级的想法吗?

enter image description here

最佳答案

enter image description here

    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"] 部分是因为您还希望在用户按完成并向下一行时增加行号。

关于iphone - UITextView 就像 Mail.app 回复 View 中一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19955959/

相关文章:

objective-c - UIWebview 旋转+转换问题

iphone - 配置门户上开发和分发配置文件的区别?

iOS 应用程序提交产生 "invalid toolchain"尽管 Xcode 是最新的

android - 如何将在 Eclipse 中使用 PhoneGap 制作的现有 Android 应用程序转换为 iPhone?

ios - UISearchBar:根据iOS版本不同的风格

iphone - iOS UIWebView 大小基于窗口

iphone - 创建动态填充 NSMutableArrays 的 NSMutableDictionary

objective-c - 从一个 UICollectionViewLayout 切换到另一个时的自定义动画?

ios - iOS 6 上的 allowsAirPlayVideo 属性

ios - WKWebView中如何访问WKWebView的内容?