0

I'm doing a Netflix clone & configure this navigation bar in swift UIKit & I got stuck at adding the logo on the left side of the navbar. Still, it ended in the centre whatever way i do it titleview or leftbarbuttonitem it results the same.

here is my first attempt, I hope someone helps me

private func configerNavBar() {
        
        var image = UIImage(named: "netflixLogo")
        // to always keep the orginal image color
        image = image?.withRenderingMode(.alwaysOriginal)
        
        let space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        space.width = 55.0
        
        navigationItem.leftBarButtonItems = [
        UIBarButtonItem(image: image, style: .plain, target: self, action: nil),
        space
        ]
        // adding nav bar button for play and profile
        navigationItem.rightBarButtonItems = [
            UIBarButtonItem(image: UIImage(systemName: "person"), style: .plain, target: self, action: nil),
            UIBarButtonItem(image: UIImage(systemName: "play.rectangle"), style: .plain, target: self, action: nil)
        ]
        
        navigationController?.navigationBar.tintColor = .white
        navigationController?.navigationBar.contentMode = .scaleAspectFit
        navigationController?.navigationBar.clipsToBounds = true
    }

and my second attempt

private func configerNavBar() {
var image = UIImage (named: "movieIcon")
// to always keep the orginal image color
image = image?.withRenderingMode(alwaysOriginal)
var imageView = UIImageView (image: image)
imageView.contentMode = .scaleAspectFit
//adding nav bar titleView to display logo image
navigationItem.titleView = imageView
// adding nav bar button for play and profile
navigationItem.rightBarButtonItems = [
UIBarButtonItem(image: UTImage (systemName: "person"), style: .done, target: self, action: nil),
UIBarButtonItem(image: UIImage (systemName: "play.rectangle"), style: .done, target: self, action: nil)
]

navigationController?.navigationBar.tintColor=.white navigationController?.navigationBar.contentMode=.scalespectFit

enter image description here

enter image description here

it shloud give me this result

enter image description here

0 Answers0