I'm trying to override programmatically the rightButton of a navigation item with a static image in order to achive this:
The following code does not give any errors but nothing is displayed in the navigation bar.
import UIKit
import Foundation
class UICipNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
// Add BPT LOGO as UIBarButton
let logoBPT = UIImage(named: "Logo BPT")?.withRenderingMode(.alwaysOriginal)
let logoBPTBarButton = UIBarButtonItem(image: logoBPT, style: .plain, target: nil, action: nil)
self.navigationItem.rightBarButtonItem = logoBPTBarButton
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
.
import UIKit
class UICipNavigationBar: UINavigationBar {
override init(frame: CGRect){
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.tintColor = UIColor.white
self.setBackgroundImage(UIImage.fromColor(color: UIColorFromHex(rgbValue: 0xffffff, alpha: 0.2)), for: UIBarMetrics.default)
self.shadowImage = UIImage()
self.isTranslucent = true
self.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont(name: "Lato-Regular", size: 24)!]
}
override func sizeThatFits(_ size: CGSize) -> CGSize {
let newSize :CGSize = CGSize(width: self.superview!.bounds.size.width, height: 60)
return newSize
}
}
I also tried to inspect the views but it seems that nothing is added: