Error on adding UINavigationbar button with image

前端 未结 1 1602
迷失自我
迷失自我 2021-01-28 01:36

I\'m trying to add an UIBarbutton with image on my UINavigationbar. However, the button moves to the center instead of keep on the left, also the image becomes huge. Can you guy

相关标签:
1条回答
  • 2021-01-28 02:20

    Custom Left-bar button image :

        let btnBack = UIButton()
        btnBack.setImage(#imageLiteral(resourceName: "back"), for: .normal)
        btnBack.frame = CGRect.init(x: 0, y: 0, width: 30, height: 30)
        btnBack.addTarget(self, action: #selector(addTapped), for: .touchUpInside)
        btnBack.imageView?.contentMode = .scaleAspectFit
        let leftBack = UIBarButtonItem.init(customView: btnBack)
    
        navigationItem.leftBarButtonItem = leftBack
    

    Also check the size of image which you are trying to set for left-bar button. I used 35 x 35 for 2x image and 53 x 53 size for 3x image.

    0 讨论(0)
提交回复
热议问题