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)))
}
self.isUserInteractionEnabled = trueininit