ios – Round UIBarButtonItem button picture get stretched

Added round button on self.navigationItem.leftBarButtonItem for particular UIViewController of a TabBarcontroller after switching one tab and getting again to particular tab. The round button is stretched.

override func viewDidLoad() {
    infoButton = UIButton(body: CGRect(x: 0, y: 0, width: 40, top: 40))
    infoButton.sd_setBackgroundImage(with: URL(string: ""), for: .regular)
    infoButton.addTarget(self, motion: #selector(menuButtonPressed), for: .touchUpInside)
    infoButton.layer.cornerRadius = infoButton.bounds.measurement.width / 2
    infoButton.clipsToBounds = true
    infoButton.layer.borderWidth = 1.0
    infoButton.imageView?.contentMode = .scaleToFill
    infoButton.layer.borderColor = UIColor.init(hexString: "#AAC8FF").cgColor
    let infoItem = UIBarButtonItem(customView: infoButton)
    self.navigationItem.leftBarButtonItem = infoItem

Error Picture:
enter image description here

Leave a Reply