UISearchBar 可以与 UITextView 一起使用吗?

发布于 2024-11-15 22:01:01 字数 436 浏览 11 评论 0原文

我一直在寻找集成 UISearchBar 和 UITextView 的教程,但没有任何可用。这让我想知道,这可能吗?我编写了以下代码:

- (IBAction)fileAction:(id)sender {

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"LICENSE" ofType:@"txt"];
    [textView setText:[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]];
}

在阅读名为 License.txt 的文档时,

我想将搜索栏集成到视图中,但如何使其工作?如何在文本文件中显示搜索结果?这可能吗?谁能给我提供此集成的示例代码?

I have been looking for a tutorial that integrates UISearchBar and UITextView and nothing is available. This makes me wonder, is this possible? I have wrote the following code:

- (IBAction)fileAction:(id)sender {

    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"LICENSE" ofType:@"txt"];
    [textView setText:[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]];
}

Where I am reading the document named License.txt

I want to integrate a Search Bar to the View, but how do I make it work? How can I display the results of the search within the Text File? Is this possible? Can anyone provide me with a sample code of this integration?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〃温暖了心ぐ 2024-11-22 22:01:01

我不太清楚你想做什么。如果您想以某种方式突出显示 UITextView 中的搜索文本,则不能。它不支持格式化文本。您必须将 WebView 与 HTML 结合使用,或将 CoreText 与 NSAttributedString 结合使用。

I'm not quite clear on what you want to do. If you want to highlight somehow the search text in a UITextView, you can't. It doesn't support formatted text. You have to use a WebView with HTML or use CoreText with an NSAttributedString.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文