UISearchBar 可以与 UITextView 一起使用吗?
我一直在寻找集成 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太清楚你想做什么。如果您想以某种方式突出显示 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.