Saturday, November 7, 2026
HomeiOS Developmentios - Add Picture as an alternative of largeTitle in NavigationBar

ios – Add Picture as an alternative of largeTitle in NavigationBar

[ad_1]

iOS 13.0-iOS 15.0+, Xcode 13.2 Beta

So, I figured it out. I made a realization with a customized NavigationBar:

public class NavigationBar: UINavigationBar {
    non-public lazy var someImageView: UIImageView = {
        let largeTitleImage = UIImageView(picture: UIImage(named: "some_image"))
        largeTitleImage.contentMode = .scaleAspectFit
        return largeTitleImage
    }()
    ...
    override public func layoutSubviews() {
        tremendous.layoutSubviews()
        setupAttributesForLargeTitle()
    }
    ...
    non-public func setupAttributesForLargeTitle() {
        if let largeTitle = subviews.filter({ NSStringFromClass(sort(of: $0)).accommodates("LargeTitleView") }).first {
            for subview in largeTitle.subviews {
                if *Some boolean worth indicating largeTitle* {
                    subview.addSubview(someImageView)
                } else {
                    ...
                }
            }
        }
    }
    ...
}

Briefly: I get to the deepest view in hierarchy of NavBar views and including new subview with picture to this hierarchy

Essential notice:

Do not use with this hack:

navigationItem.title

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments