From 91df3c5592c2c50a017d745811e2629811bd671d Mon Sep 17 00:00:00 2001 From: Alexander Karpov Date: Thu, 17 Aug 2017 16:33:39 +0300 Subject: [PATCH 1/2] Added multiline support to search queries --- Stepic/SearchQueriesViewController.swift | 2 ++ Stepic/SearchSuggestionTableViewCell.xib | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Stepic/SearchQueriesViewController.swift b/Stepic/SearchQueriesViewController.swift index 5d86d8a62c..849e0e8984 100644 --- a/Stepic/SearchQueriesViewController.swift +++ b/Stepic/SearchQueriesViewController.swift @@ -49,6 +49,8 @@ class SearchQueriesViewController: UIViewController { super.viewDidLoad() tableView.delegate = self tableView.dataSource = self + tableView.estimatedRowHeight = 44 + tableView.rowHeight = UITableViewAutomaticDimension self.view.addSubview(tableView) tableView.align(to: self.view) tableView.register(UINib(nibName: "SearchSuggestionTableViewCell", bundle: nil), forCellReuseIdentifier: "SearchSuggestionTableViewCell") diff --git a/Stepic/SearchSuggestionTableViewCell.xib b/Stepic/SearchSuggestionTableViewCell.xib index 9c43068897..e9b07ba1a0 100644 --- a/Stepic/SearchSuggestionTableViewCell.xib +++ b/Stepic/SearchSuggestionTableViewCell.xib @@ -4,7 +4,6 @@ - @@ -19,8 +18,8 @@ - - + - + From b91f3320185011fefaffa3e6a3a4eeb2cf949eff Mon Sep 17 00:00:00 2001 From: Alexander Karpov Date: Thu, 17 Aug 2017 17:13:27 +0300 Subject: [PATCH 2/2] Added query highlight to search queries --- Stepic/SearchQueriesViewController.swift | 2 +- Stepic/SearchSuggestionTableViewCell.swift | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Stepic/SearchQueriesViewController.swift b/Stepic/SearchQueriesViewController.swift index 849e0e8984..88b34b3b62 100644 --- a/Stepic/SearchQueriesViewController.swift +++ b/Stepic/SearchQueriesViewController.swift @@ -89,7 +89,7 @@ extension SearchQueriesViewController: UITableViewDataSource { return UITableViewCell() } - cell.suggestion = suggestions[indexPath.row] + cell.set(suggestion: suggestions[indexPath.row], query: query) return cell } } diff --git a/Stepic/SearchSuggestionTableViewCell.swift b/Stepic/SearchSuggestionTableViewCell.swift index 1eefafa2e3..547043e068 100644 --- a/Stepic/SearchSuggestionTableViewCell.swift +++ b/Stepic/SearchSuggestionTableViewCell.swift @@ -12,10 +12,18 @@ class SearchSuggestionTableViewCell: UITableViewCell { @IBOutlet weak var suggestionLabel: UILabel! - var suggestion: String = "" { - didSet { - suggestionLabel.text = suggestion + func set(suggestion: String, query: String) { + let fontSize: CGFloat = 17 + var bold = UIFont.boldSystemFont(ofSize: fontSize) + if #available(iOS 8.2, *) { + bold = UIFont.systemFont(ofSize: fontSize, weight: UIFontWeightMedium) } + let regular = UIFont.systemFont(ofSize: fontSize) + let attributedSuggestion = NSMutableAttributedString(string: suggestion, attributes: [NSFontAttributeName: regular, NSForegroundColorAttributeName: UIColor.gray]) + if let queryLocation = suggestion.indexOf(query.lowercased()) { + attributedSuggestion.addAttributes([NSFontAttributeName: bold, NSForegroundColorAttributeName: UIColor.black], range: NSRange(location: queryLocation, length: query.characters.count)) + } + suggestionLabel.attributedText = attributedSuggestion } override func awakeFromNib() {