Created
June 26, 2018 00:29
-
-
Save aybekckaya/544220d349870d4605b0b8b7ed464253 to your computer and use it in GitHub Desktop.
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
enum NavigationBarType { | |
case closeOnRight | |
} | |
class BaseViewController: UIViewController { | |
fileprivate static let barButtonSize = CGSize(width: 30, height: 30) | |
fileprivate enum NavigationBarButtonType { | |
case closeBtn | |
func view(vc:BaseViewController)->UIBarButtonItem { | |
switch self { | |
case .closeBtn: | |
let customView:UIView = UIView() | |
customView.frame = CGRect(x: 0, y: 0, width: BaseViewController.barButtonSize.width, height: BaseViewController.barButtonSize.height) | |
let image:UIImage = #imageLiteral(resourceName: "checkoutNavClose") | |
let btn = UIButton(type: UIButtonType.custom) | |
btn.frame = CGRect(x: 0, y: 0, width: customView.frame.size.width, height: customView.frame.size.height) | |
btn.setImage(image, for: UIControlState.normal) | |
btn.center = CGPoint(x: customView.frame.size.width / 2, y: customView.frame.size.height / 2 ) | |
btn.addTarget(vc, action: #selector(dismissViewController), for: UIControlEvents.touchUpInside) | |
customView.addSubview(btn) | |
return UIBarButtonItem(customView: customView) | |
} | |
} | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
updateNavigationBar() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
// Navigation Bar | |
extension BaseViewController { | |
func updateNavigationBar() { | |
switch self { | |
case is CustomTransitionVCDetail: navigationBarWithCloseOnRight() | |
default: break | |
} | |
} | |
private func navigationBarWithCloseOnRight () { | |
let btnItemRight = NavigationBarButtonType.closeBtn.view(vc: self) | |
self.navigationItem.rightBarButtonItems = [btnItemRight] | |
} | |
} | |
// Navigation Bar Button Blue Prints | |
extension BaseViewController { | |
@objc func dismissViewController () { | |
self.dismiss(animated: true, completion: nil) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment