Skip to content

Instantly share code, notes, and snippets.

@bharathreddys77
Last active October 27, 2020 11:19
Show Gist options
  • Save bharathreddys77/0e8bf05588adfacf0b8d0ec307d6182c to your computer and use it in GitHub Desktop.
Save bharathreddys77/0e8bf05588adfacf0b8d0ec307d6182c to your computer and use it in GitHub Desktop.
Type of Navigation bar
//Define different types of navigation bar application requires
enum NavigationbarType {
case NavPlainBackButton
case NavCenterTitleImageWithNoBackButton
case NavCenterTitleWithBackButton
case NavWithTitleOnly
case NavWithLocationSearch
}
//create a protocol which takes input of navigation type and selectors
protocol CustomNavigationBarProtocol {
func setNavigationbartype(_ type:NavigationbarType,pageTitle:String?,leftSelector:Selector,rightSelector:Selector?) -> Any?
}
//Write extension for above protocol
extension CustomNavigationBarProtocol where Self:UIViewController {
@discardableResult
func setNavigationbartype(_ type:NavigationbarType,pageTitle:String?,leftSelector:Selector,rightSelector:Selector?) -> Any? {
switch navType {
case .NavCenterTitleImageWithNoBackButton:
setImageAsNavTitleView()
case .NavCenterTitleWithBackButton:
setTitleViewOfpage(title: centerTitle!,leftSelector: leftSelector!)
case .NavPlainBackButton:
setOriginalBackImage(selector: leftSelector!)
case .NavWithTitleOnly:
setOnlyTitleWithoutBackButton(title: centerTitle ?? "")
case .NavWithLocationSearch:// search bar will be returned
return showLocationSearchOnNavBar(leftSelector: leftSelector!)
}
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment