4

我在 iPhone 应用程序中工作,例如 iMessage 原生应用程序。我设计了一个看起来像 iMessage 的页面,还添加了一个气泡。我是怎么做的,只是添加了一个UITextView in UITableView Cell and also i have added UIImageView on UITextView with bubble images.

从 NSMutableArray 将文本加载到 UITextView。它工作正常。现在我的疑问是:

  1. 在 iMessage 应用程序中,他们设置了when the user hold the bubble they making the text as selectable and showing Copy option. 在我的应用程序when the user hold a bubble the Copy option showing but some particular text only copying中。如何选择所有文本并向用户显示复制选项?

  2. 在 iMessage 应用程序中,选择区域(选择开始和选择结束两行)未显示。但在我的应用程序中selection regions are showing how can i manage that?

你能帮我解决这个问题吗?提前致谢。

4

2 回答 2

7

最后我解决了我在下面代码中使用的问题。现在可以从 UITextView 中选择所有内容并向用户显示复制选项以复制消息。请找到代码供您参考。

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(copy:))
    {
        [self selectAll:self];

        return YES;
    }
    else if (action == @selector(cut:))
    {
        return NO;
    } 
        return NO;
}


- (void)copy:(id)sender 
{
    UIPasteboard *pastBoard = [UIPasteboard generalPasteboard];
    [pastBoard setString:self.text];
    self.selectedTextRange = nil;
}

快乐编码。

于 2012-09-14T12:59:26.880 回答
1

在这里,如何选择文本UITextView

[textView setSelectedRange:NSMakeRange(row, length)];

where,row表示您要从哪一行开始选择。length是文本的总长度。

e.g. [textView setSelectedRange:NSMakeRange(1, 45)]; // where 1 is first row, and 45 is length of text of selection.
于 2012-09-13T10:20:50.907 回答