I have a problem where when I add a button from a closure the function does not execute:
Here I create the button (Close Button):
private let CloseButton: UIButton = {
let button = UIButton(type: .system)
button.setTitle("X", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 34)
button.setTitleColor(.red, for: .normal)
button.addTarget(self, action: #selector(closeTest), for: .touchUpInside)
return button
}()
Here is the function:
@objc private func closeTest(_ sender: UIButton) {
print("Test")
}
Here are the constraints:
topContainer.addSubview(CloseButton)
CloseButton.centerXAnchor.constraint(equalTo: topContainer.centerXAnchor).isActive = true
CloseButton.centerYAnchor.constraint(equalTo: topContainer.centerYAnchor).isActive = true
CloseButton.heightAnchor.constraint(equalTo: topContainer.heightAnchor, multiplier: 0.8).isActive = true