Skip to content

Commit

Permalink
Merge pull request twostraws#240 from jaypen7/Glossary_SearchKeywords…
Browse files Browse the repository at this point in the history
…Highlighting

Glossary search keywords highlighting
  • Loading branch information
twostraws authored Sep 23, 2022
2 parents aa88d57 + 4386c32 commit 88cfe90
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Unwrap/Activities/Learn/Glossary/GlossaryDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ class GlossaryDataSource: NSObject, UITableViewDataSource, UISearchResultsUpdati
let key = sectionTitles[indexPath.section]
if let entries = sortedEntries[key] {
let entry = entries[indexPath.row]
cell.textLabel?.text = entry.term

/// Add highlighting of search keywords
let attrText = NSMutableAttributedString(string: entry.term)
if let searchText = delegate?.navigationItem.searchController?.searchBar.text, let highlightRange = attrText.string.range(of: searchText, options: .caseInsensitive, range: nil, locale: nil) {
let nsRange = NSRange(highlightRange, in: attrText.string)
attrText.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.systemYellow, NSAttributedString.Key.font: Unwrap.scaledExtraBoldFont], range: nsRange)
}
cell.textLabel?.attributedText = attrText

cell.detailTextLabel?.attributedText = entry.description.fromSimpleHTML()
}

Expand Down

0 comments on commit 88cfe90

Please sign in to comment.