使用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发布于 2020-01-16 00:05:24
您在navigation bar中添加按钮,并将clipToBounds设置为profileImage,将角半径提供给按钮而不是图像将解决您的问题。当前您的按钮大小为36x36
https://stackoverflow.com/questions/59753799
复制相似问题