I have a UIButton
extension to make some of my buttons have a round shape:
extension UIButton {
override open var intrinsicContentSize: CGSize {
let originalContentSize = super.intrinsicContentSize
let height = originalContentSize.height + 5
layer.cornerRadius = height / 2
layer.masksToBounds = true
return CGSize(width: originalContentSize.width + 35, height: height)
}
}
This works as intended for the buttons within my views. However, I also have some buttons in my navigation bars, which have been affected by this extension and now appear in their containers with extra padding that is rather unsightly.
This is how I usually create my navigation bar buttons:
private func navBarButton() -> UIBarButtonItem {
let button = UIBarButtonItem(image: UIImage(named: "x"), style: .plain, target: self, action: #selector(x))
button.tintColor = .black
return button
}
Before I added my extension to the UIButton
class, my navbar buttons used to look like this:
Now, they look like this:
which I do not want. How do I make my navbar buttons go back to what they looked like before adding my extension?