Skip to content

Commit

Permalink
Add a variable to disable highlight attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianeEnnaji committed Jun 18, 2018
1 parent 97cb555 commit dc63bd6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions SearchTextField/Classes/SearchTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ open class SearchTextField: UITextField {
/// Set your custom set of attributes in order to highlight the string found in each item
open var highlightAttributes: [NSAttributedStringKey: AnyObject] = [.font: UIFont.boldSystemFont(ofSize: 10)]

/// Disable highlight attributes
open var forceNoHighlightAttributes = false

/// Start showing the default loading indicator, useful for searches that take some time.
open func showLoadingIndicator() {
self.rightViewMode = .always
Expand Down Expand Up @@ -439,10 +442,12 @@ open class SearchTextField: UITextField {
item.attributedTitle = NSMutableAttributedString(string: item.title)
item.attributedSubtitle = NSMutableAttributedString(string: (item.subtitle != nil ? item.subtitle! : ""))

item.attributedTitle!.setAttributes(highlightAttributes, range: titleFilterRange)

if subtitleFilterRange.location != NSNotFound {
item.attributedSubtitle!.setAttributes(highlightAttributesForSubtitle(), range: subtitleFilterRange)
if !forceNoHighlightAttributes {
item.attributedTitle!.setAttributes(highlightAttributes, range: titleFilterRange)

if subtitleFilterRange.location != NSNotFound {
item.attributedSubtitle!.setAttributes(highlightAttributesForSubtitle(), range: subtitleFilterRange)
}
}

filteredResults.append(item)
Expand Down

0 comments on commit dc63bd6

Please sign in to comment.