ios - How can I set a logo in the navigation bar for all view controllers from a central place -
how can set logo in navigation bar view controllers central place? mean, wouldn't set logo in code of every view controller (viewdidload()) method. there place put that, appdelegate or event fired after every screen change? put code below in appdelegate worked initial screen. thanks.
let img = uiimageview(image: uiimage(named: "tourney")) img.contentmode = .scaleaspectfit let logo = uibarbuttonitem(customview: img) let root = window?.rootviewcontroller! root?.childviewcontrollers[0].childviewcontrollers[0].navigationitem.rightbarbuttonitem = logo
extension uiviewcontroller , adding method setupnavigationbar
setup navigation center image .
extension uiviewcontroller { func setupnavigationbar(image: uiimage) { //set image navigation bar center //set titile //self.navigationitem.title = title //set image in center self.navigationitem.titleview = uiimageview(image: image) } }
now setupnavigationbar
viewcontroller , try call way
override func viewdidload() { super.viewdidload() self.setupnavigationbar(image: uiimage(named: "tourney")) }
Comments
Post a Comment