Created
November 9, 2015 02:51
-
-
Save rajohns08/771e756fe47d256bcb57 to your computer and use it in GitHub Desktop.
iOS / Swift - A base view controller for dismissing keyboard and applying color theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class BaseViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
listenForTapsOnViewToDismissKeyboard() | |
applyGlobalColorTheme() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
} | |
func listenForTapsOnViewToDismissKeyboard() { | |
let tapRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard") | |
self.view.addGestureRecognizer(tapRecognizer) | |
} | |
func dismissKeyboard() { | |
self.view.endEditing(true) | |
} | |
private func applyGlobalColorTheme() { | |
setBackgroundColor() | |
styleNavBar() | |
} | |
private func setBackgroundColor() { | |
self.view.backgroundColor = UIColor.grayColor() | |
} | |
private func styleNavBar() { | |
setNavBarColor() | |
setNavBarTitleTextColor() | |
setNavBarBackTextColor() | |
} | |
private func setNavBarColor() { | |
self.navigationController?.navigationBar.barTintColor = UIColor.lightGrayColor() | |
} | |
private func setNavBarTitleTextColor() { | |
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.grayColor()] | |
} | |
private func setNavBarBackTextColor() { | |
self.navigationController?.navigationBar.tintColor = UIColor.blueColor() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment