I found a post with similar a question but they weren't answered properly, or weren't answered at all. This piece of code was working fine in Swift 2.2 but now all the sudden it is not working in Swift 4. The UIBarButtonItem image is being stretched, completely blocking the title.
let imageData = (trans.value(forKey: "profilePicture")) as? Data
storedImage = UIImage.init(data: imageData!)
let button = UIButton.init(type: .custom)
button.setImage((storedImage), for: UIControlState.normal)
button.addTarget(self, action: #selector(ParentViewController.buttonPressed), for: UIControlEvents.touchUpInside)
button.frame = CGRect(x: 0, y: 0, width: 25, height: 25)
button.layer.cornerRadius = 0.5 * button.bounds.size.width
button.clipsToBounds = true
button.layer.borderWidth = 1
//button.layer.borderColor = UIColor(red: 178/255, green: 0/255, blue: 0/255, alpha: 1).cgColor
button.layer.borderColor = UIColor.white.cgColor
let barButton = UIBarButtonItem(customView: button)
self.navigationItem.leftBarButtonItem = barButton