iOS: UIButton Appearing, But Not Functioning On UIView

There are some similar questions out there on this, but they’re in Obj-C and don’t specifically answer my question.

I’m building a Tinder-like dating application with a button on the card that allows the current user to view more info about the user on the displayed card. I’ve written this button (moreInfoButton) programmatically and have it displayed on the card (UIView) without a problem. But when I click on the button, it does not function. I’ve tried isEnabled and isUserInteractionEnabled, but neither work. Here’s my code:

import UIKit import SDWebImage  class CardView: UIView {  var imageView = UIImageView(image: #imageLiteral(resourceName: "lady5c"))  var informationLabel = UILabel()  var images: [String]?  var userId: String?  var stackView: UIStackView?  let moreInfoButton: UIButton = {     let button = UIButton(type: .system)     button.setImage(#imageLiteral(resourceName: "info_icon").withRenderingMode(.alwaysOriginal), for: .normal)     return button }()  override init(frame: CGRect) {     super.init(frame: frame)     layer.cornerRadius = 15     clipsToBounds = true      imageView.contentMode = .scaleAspectFill     addSubview(imageView)     imageView.fillSuperview()      addSubview(informationLabel)     informationLabel.numberOfLines = 0     informationLabel.anchor(top: nil, leading: leadingAnchor, bottom: bottomAnchor, trailing: trailingAnchor, padding: .init(top: 0, left: 16, bottom: 16, right: 16))     informationLabel.text = ""     informationLabel.textColor = .white     informationLabel.layer.zPosition = 1      addSubview(moreInfoButton)     moreInfoButton.anchor(top: nil, leading: nil, bottom: bottomAnchor, trailing: trailingAnchor, padding: .init(top: 0, left: 0, bottom: 20, right: 20), size: .init(width: 50, height: 50))     moreInfoButton.layer.zPosition = 1     moreInfoButton.isUserInteractionEnabled = true      // let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan))     // addGestureRecognizer(panGesture)     addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleTap)))  } 

UIButton in CollectionViewCell is not responding or calling the action (tvOS)

I have been searching and checking like over 50 topics and GitHub examples but still no solution for this and I’m still stuck.

I’m trying to put a UIButton in CollectionViewCell and perform the action, but is seems that it is not being selected and is not responding to anything.

I have been trying delegate protocol on cell from examples and topics, I have been calling the action from selector, show subview and resize lots of tings and much more, but still the same.

Is it a bug or what I’m doing wrong?

I’m showing a basic example where it reproduces this issue.

class CollectionViewCell: UICollectionViewCell {      @IBOutlet weak var addButton: UIButton!  }  class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {  @IBOutlet weak var collectionView: UICollectionView!  override func viewDidLoad() {     super.viewDidLoad() }  @objc func yourFunc(sender : UIButton){     print("Working!") }  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {     return 1 }  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for:         indexPath) as! CollectionViewCell      cell.addSubview(cell.addButton)      cell.addButton.tag = indexPath.item      cell.addButton.addTarget(self, action: #selector(self.yourFunc), for: .primaryActionTriggered)      return cell } 

UIButton custom class

tengo la siguiente custom class de un UIButton, pero al agregarla a un botón en xcode no logro hacer que los cambios se vean reflejados, alguien sabe cuál es el problema?

   import UIKit   class BotonBordesRedondeados: UIButton {    // Only override draw() if you perform custom drawing.  // An empty implementation adversely affects performance during animation.  /*override func draw(_ rect: CGRect) {  // Drawing code     setup()  }*/   override init(frame: CGRect) {     super.init(frame: frame)     setup() } required public init?(coder aDecoder: NSCoder) {     super.init(coder: aDecoder)     setup() }   func setup () {       self.layer.backgroundColor = ColorUtils.hexStringToUIColor(hex: "#6B00FF") as! CGColor      self.backgroundColor = ColorUtils.hexStringToUIColor(hex: "#6B00FF")      layer.borderColor = ColorUtils.hexStringToUIColor(hex: "#6B00FF").cgColor     layer.cornerRadius = 20     layer.borderWidth = 2.0  }  }