Skip to content

Commit dc63bd6

Browse files
Add a variable to disable highlight attributes
1 parent 97cb555 commit dc63bd6

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

SearchTextField/Classes/SearchTextField.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ open class SearchTextField: UITextField {
8080
/// Set your custom set of attributes in order to highlight the string found in each item
8181
open var highlightAttributes: [NSAttributedStringKey: AnyObject] = [.font: UIFont.boldSystemFont(ofSize: 10)]
8282

83+
/// Disable highlight attributes
84+
open var forceNoHighlightAttributes = false
85+
8386
/// Start showing the default loading indicator, useful for searches that take some time.
8487
open func showLoadingIndicator() {
8588
self.rightViewMode = .always
@@ -439,10 +442,12 @@ open class SearchTextField: UITextField {
439442
item.attributedTitle = NSMutableAttributedString(string: item.title)
440443
item.attributedSubtitle = NSMutableAttributedString(string: (item.subtitle != nil ? item.subtitle! : ""))
441444

442-
item.attributedTitle!.setAttributes(highlightAttributes, range: titleFilterRange)
443-
444-
if subtitleFilterRange.location != NSNotFound {
445-
item.attributedSubtitle!.setAttributes(highlightAttributesForSubtitle(), range: subtitleFilterRange)
445+
if !forceNoHighlightAttributes {
446+
item.attributedTitle!.setAttributes(highlightAttributes, range: titleFilterRange)
447+
448+
if subtitleFilterRange.location != NSNotFound {
449+
item.attributedSubtitle!.setAttributes(highlightAttributesForSubtitle(), range: subtitleFilterRange)
450+
}
446451
}
447452

448453
filteredResults.append(item)

0 commit comments

Comments
 (0)