Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search Queries enhancements #87

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Stepic/SearchQueriesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -87,7 +89,7 @@ extension SearchQueriesViewController: UITableViewDataSource {
return UITableViewCell()
}

cell.suggestion = suggestions[indexPath.row]
cell.set(suggestion: suggestions[indexPath.row], query: query)
return cell
}
}
Expand Down
14 changes: 11 additions & 3 deletions Stepic/SearchSuggestionTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
9 changes: 4 additions & 5 deletions Stepic/SearchSuggestionTableViewCell.xib
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -19,18 +18,18 @@
<rect key="frame" x="0.0" y="0.0" width="320" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aer-63-xtx">
<rect key="frame" x="16" y="8" width="296" height="28"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="249" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="aer-63-xtx">
<rect key="frame" x="16" y="12" width="296" height="19.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstAttribute="leadingMargin" secondItem="aer-63-xtx" secondAttribute="leading" constant="-8" id="Jsr-Z8-Iem"/>
<constraint firstAttribute="topMargin" secondItem="aer-63-xtx" secondAttribute="top" id="MOv-8x-kcc"/>
<constraint firstAttribute="topMargin" secondItem="aer-63-xtx" secondAttribute="top" constant="-4" id="MOv-8x-kcc"/>
<constraint firstAttribute="trailingMargin" secondItem="aer-63-xtx" secondAttribute="trailing" id="bfz-Dr-5Ap"/>
<constraint firstAttribute="bottomMargin" secondItem="aer-63-xtx" secondAttribute="bottom" id="lsY-28-ElR"/>
<constraint firstAttribute="bottomMargin" secondItem="aer-63-xtx" secondAttribute="bottom" constant="4" id="lsY-28-ElR"/>
</constraints>
</tableViewCellContentView>
<connections>
Expand Down