I have been searching and trying for days but since it's a new thing there's not much information available (or I can't find them).
Anyway, I am trying to get use of new NavBar features in iOS 11
but I want to put both a logo and a large title (of each ViewController
) in my NavBar
. Something like the screenshot below:
How is it possible to implement this?
Side Hint:
For same app
in iOS 10
I set the logo to show instead of titleView
in NavBar
but now in newer version we want to add the Title too.
Thanks in advance
Without your code sample it's hard to say what goes wrong for you, but this just works:
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 11, *) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationItem.largeTitleDisplayMode = .always
title = "Your title"
}
let titleImageView = NavigationImageView()
titleImageView.image = UIImage(named: "yourImageName")
navigationItem.titleView = titleImageView
}
EDIT : To set custom size for your title view you can subclass your UIView
(UIImageView) and override sizeThatFits
class NavigationImageView: UIImageView {
override func sizeThatFits(_ size: CGSize) -> CGSize {
return CGSize(width: 50, height: 50)
}
}
Did you try setting a background image for your navbar? Like this:
// Set Navigation bar background Image
let navBgImage:UIImage = UIImage(named: "[image.jpg]")!
self.navigationController!.navigationBar.setBackgroundImage(navBgImage, for: .default)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.