2

I don't know what's wrong with my code or what did I did that leads to this I spent half an hour trying to figure out what's wrong with my code but I have no idea, I'm calling this func in viewDidLoad()

func setupNavBarBtn(){
        
        let backBtn = UIButton(type: .system)
        backBtn.setImage(#imageLiteral(resourceName: "cellarrow").withRenderingMode(.alwaysOriginal), for: .normal)
        backBtn.contentMode = .scaleAspectFit
        backBtn.frame = CGRect(x: 0, y: 0, width: 30, height: 30)

        let callBtn = UIButton(type: .system)
        callBtn.setImage(#imageLiteral(resourceName: "Call").withRenderingMode(.alwaysOriginal), for: .normal)
        callBtn.contentMode = .scaleAspectFit
        callBtn.frame = CGRect(x: 0, y: 0, width: 30, height: 30)

        self.navigationItem.leftBarButtonItems = [UIBarButtonItem(customView: backBtn), UIBarButtonItem(customView: callBtn)]

}

enter image description here

1 Answers1

1

You should create UIBarButtonItem instead of UIButton:

let backBtn = UIBarButtonItem(image:UIImage(named: "cellarrow.png"), style: .plain, target: nil, action: nil)
let callBtn = UIBarButtonItem(image:UIImage(named: "Call.png"), style: .plain, target: nil, action: nil)
self.navigationItem.leftBarButtonItems = [backBtn,callBtn]

The size of bar button should better be 20x20

Ptit Xav
  • 3,006
  • 2
  • 6
  • 15