作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在我的 pdf View 中设置了一个搜索栏,可以突出显示我要查找的词。当我尝试删除突出显示以便搜索新词时。我试图扭转我所做的,将颜色更改为白色,并删除注释但没有任何效果。我想在用户单击取消按钮时清除突出显示。我究竟做错了什么?
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
i = 0
unhighlight(searchTerms: [searchWord])
searchBar.text! = ""
}
private func highlight(searchTerms: [String]?)
{
searchTerms?.forEach { term in
selections = pdfView.document?.findString(term, withOptions: [.caseInsensitive])
selections?.forEach { selection in
selection.pages.forEach { page in
highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
highlight.endLineStyle = .square
highlight.color = UIColor.orange.withAlphaComponent(0.5)
page.addAnnotation(highlight)
}
}
}
}
func unhighlight(searchTerms: [String]?)
{
searchTerms?.forEach { term in
selections = pdfView.document?.findString(term, withOptions: [.caseInsensitive])
selections?.forEach { selection in
selection.pages.forEach { page in
highlight = PDFAnnotation(bounds: selection.bounds(for: page), forType: .highlight, withProperties: nil)
highlight.endLineStyle = .square
highlight.color = UIColor.white.withAlphaComponent(0.5)
page.addAnnotation(highlight)
}
}
}
}
最佳答案
不确定您是否解决了您的问题,但我相信您只是将这些注释传递给 PDFView 内置的 self.highlightedselections 数组。将该数组设置为 nil 应该清除高亮显示,而不是创建您自己的注释。
在搜索时,它应该提供一个 PDFSelection,您可以在其中设置 .color 属性
关于ios - 如何删除突出显示的 pdf 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57567233/
有没有一种方法可以“标记”对象的属性,使它们在反射中“突出”? 例如: class A { int aa, b; string s1, s2; public int AA
我是一名优秀的程序员,十分优秀!