Skip to content

Instantly share code, notes, and snippets.

@bharathreddys77
Created October 27, 2020 11:28
Show Gist options
  • Save bharathreddys77/f7bbd6b42da34652edc9683ef31bd41f to your computer and use it in GitHub Desktop.
Save bharathreddys77/f7bbd6b42da34652edc9683ef31bd41f to your computer and use it in GitHub Desktop.
Navigation bar items
fileprivate func setOriginalBackImage(selector:Selector) {
let backButton = UIBarButtonItem(image: UIImage(named: "nav_back_btn")?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: selector)
backButton.tintColor?.withAlphaComponent(0.3)
self.navigationItem.leftBarButtonItem = backButton
}
fileprivate func setOnlyTitleWithoutBackButton(title:String) { // just display title on nav bar without back button
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 150, height: 44))
label.text = title
label.font = UIFont(name: Constants.MabryFonts.REGULAR, size: 16)
label.textColor = UIColor(red: 24/255, green: 36/255, blue: 52/255, alpha: 1)
label.textAlignment = .center
self.navigationItem.titleView = label
}
fileprivate func showLocationSearchOnNavBar(leftSelector:Selector) -> UITextField { // show navigation bar with text field in center
setOriginalBackImage(selector: leftSelector)
let view = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width-60, height: self.navigationController?.navigationBar.frame.size.height ?? 44))
view.backgroundColor = .clear
let field = UITextField(frame: view.frame)
field.borderStyle = .none
field.placeholder = "Find a neighbourhood, address or zip"
field.textColor = UIColor(red: 24/255, green: 36/255, blue: 52/255, alpha: 1)
field.backgroundColor = .clear
field.clearButtonMode = .whileEditing
view.addSubview(field)
self.navigationItem.titleView = view
return field
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment