使用iOS13.3、XCode11.3、
我尝试在我的 largeTitle NavigationBar 上放置一个圆形图像作为 rightBarButtonItem。
该按钮被绘制,但它没有被剪裁,并且还有一些难看的白色角落。
这是我的代码(见下文):
如您所见,我添加了clipsToBounds = true
它 - 但我没有看到边缘被剪裁。为什么 ???
if let image = image {
self.profileImage.image = image
} else {
self.profileImage.image = #imageLiteral(resourceName: "profile-placeholder-small")
}
let button = UIButton(type: .custom)
button.setImage(self.profileImage.image, for: .normal)
button.addTarget(self, action:#selector(self.callMethod), for: .touchDragInside)
button.frame = CGRect(x: 0, y: 0, width: 36, height: 36)
let barButton = UIBarButtonItem(customView: button)
self.navigationItem.rightBarButtonItem = barButton
button.translatesAutoresizingMaskIntoConstraints = false
button.widthAnchor.constraint(equalToConstant: 36).isActive = true
button.heightAnchor.constraint(equalToConstant: 36).isActive = true
self.profileImage.contentMode = .scaleAspectFit
self.profileImage.layer.cornerRadius = self.profileImage.frame.size.width / 2
self.profileImage.layer.masksToBounds = false
self.profileImage.clipsToBounds = true