UIBarButtonItem图像大小不起作用

时间:2018-07-10 19:15:16

标签: ios swift swift4 uibarbuttonitem

我发现了一个类似问题的帖子,但是没有正确回答,或者根本没有回答。这段代码在Swift 2.2中可以正常工作,但是现在突然之间在Swift 4中就无法正常工作。UIBarButtonItem图像被拉伸,完全阻塞了标题。

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

enter image description here

0 个答案:

没有答案